Skip to content

Commit

Permalink
Merge pull request #965 from terascope/add-simple-fetch-for-spaces-api
Browse files Browse the repository at this point in the history
add old fetch back as simpleFetch
  • Loading branch information
godber authored Oct 14, 2022
2 parents da330db + 69002e3 commit 8415873
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"subslice"
]
}
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ yarn global add teraslice-cli

# Step 2:
teraslice-cli assets deploy <cluster-alias> --build

```
## APIS

* [Elasticsearch Reader API](./docs/apis/elasticsearch_reader_api.md)
* [Elasticsearch Sender API](./docs/apis/elasticsearch_sender_api.md)
* [Spaces Reader API](./docs/apis/spaces_reader_api.md)
* [Elasticsearch State Storage](./docs/apis/elasticsearch_state_storage.md)
## APIS

* [Elasticsearch Reader API](./docs/apis/elasticsearch_reader_api.md)
* [Elasticsearch Sender API](./docs/apis/elasticsearch_sender_api.md)
* [Spaces Reader API](./docs/apis/spaces_reader_api.md)
* [Elasticsearch State Storage](./docs/apis/elasticsearch_state_storage.md)

## Operations
* [elasticsearch_reader](./docs/operations/elasticsearch_reader.md)
* [elasticsearch_bulk](./docs/operations/elasticsearch_bulk.md)
* [elasticsearch_data_generator](./docs/operations/elasticsearch_data_generator.md)
* [id_reader](./docs/operations/id_reader.md)
* [spaces_reader](./docs/operations/spaces_reader.md)

* [elasticsearch_reader](./docs/operations/elasticsearch_reader.md)
* [elasticsearch_bulk](./docs/operations/elasticsearch_bulk.md)
* [elasticsearch_data_generator](./docs/operations/elasticsearch_data_generator.md)
* [id_reader](./docs/operations/id_reader.md)
* [spaces_reader](./docs/operations/spaces_reader.md)

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion asset/asset.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "elasticsearch",
"version": "3.2.0"
"version": "3.3.0"
}
2 changes: 1 addition & 1 deletion asset/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asset",
"version": "3.2.0",
"version": "3.3.0",
"private": true,
"workspaces": {
"nohoist": [
Expand Down
5 changes: 5 additions & 0 deletions asset/src/elasticsearch_reader_api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ export const schema = {
}
}
},
useSimpleFetch: {
doc: 'Use the original fetch algorithm, that sets query size to windowSize without extra retry logic',
default: false,
format: Boolean
}
};

export default class Schema extends ConvictSchema<ElasticsearchReaderAPIConfig> {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elasticsearch-assets",
"description": "bundle of processors for teraslice",
"version": "3.2.0",
"version": "3.3.0",
"private": true,
"workspaces": [
"packages/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/elasticsearch-asset-apis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terascope/elasticsearch-asset-apis",
"version": "0.11.0",
"version": "0.11.1",
"description": "Elasticsearch reader and sender apis",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export class ElasticsearchReaderAPI {
* https://github.com/terascope/elasticsearch-assets/issues/948
*/
async fetch(queryParams: ReaderSlice = {}): Promise<DataEntity[]|DataFrame|Buffer> {
if (this.config.useSimpleFetch) {
return this.simpleFetch(queryParams);
}

const countExpansionFactor = 1.5;
let querySize = 10000;
const retryLimit = 5;
Expand Down Expand Up @@ -163,6 +167,22 @@ export class ElasticsearchReaderAPI {
return result;
}

async simpleFetch(queryParams: ReaderSlice = {}): Promise<DataEntity[]|DataFrame|Buffer> {
// attempt to get window if not set
if (!this.windowSize) await this.setWindowSize();

// if we did go ahead and complete query
const query = buildQuery(this.config, {
...queryParams, count: this.windowSize
});

return this.client.search(
query,
this.config.response_type ?? FetchResponseType.data_entities,
this.config.type_config
);
}

/**
* Handles multiple result types and returns the number of returned records
* @param result the object returned that contains the search results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export async function createSpacesReaderAPI({
if (config.response_type === FetchResponseType.data_frame && !config.type_config) {
config.type_config = await client.getDataType();
}
// simpleFetch should be used by the spaces reader to avoid the search size
// expansion algorithm, this is because most endpoints are configured with
// a much lower search limit than the backend clusters
config.useSimpleFetch = true;

return new ElasticsearchReaderAPI(config, client, emitter, logger);
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export interface ESReaderOptions {
starting_key_depth: number;
response_type?: FetchResponseType;
type_config?: DataTypeConfig
useSimpleFetch?: boolean;
}

export interface SpacesAPIConfig extends ESReaderOptions {
Expand Down
24 changes: 12 additions & 12 deletions test/spaces_reader/fetcher-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('spaces_reader fetcher', () => {
['range query', {
query: {
q: 'date:[2017-09-23T18:07:14.332Z TO 2017-09-25T18:07:14.332Z}',
size: 150
size: 100
},
opConfig: {
token,
Expand All @@ -60,7 +60,7 @@ describe('spaces_reader fetcher', () => {
['lucene query', {
query: {
q: '(foo:bar)',
size: 7500,
size: 5000,
},
opConfig: {
query: 'foo:bar',
Expand All @@ -75,7 +75,7 @@ describe('spaces_reader fetcher', () => {
['lucene query with url characters', {
query: {
q: '(foo:"bar+baz")',
size: 7500,
size: 5000,
},
opConfig: {
query: 'foo:"bar+baz"',
Expand All @@ -90,7 +90,7 @@ describe('spaces_reader fetcher', () => {
['lucene query with fields', {
query: {
q: '(test:query OR other:thing AND bytes:>=2000)',
size: 150,
size: 100,
fields: 'foo,bar,date'
},
opConfig: {
Expand All @@ -107,7 +107,7 @@ describe('spaces_reader fetcher', () => {
['lucene query with date range', {
query: {
q: 'example_date:[2017-09-23T18:07:14.332Z TO 2017-09-25T18:07:14.332Z} AND (foo:bar)',
size: 300,
size: 200,
},
opConfig: {
query: 'foo:bar',
Expand All @@ -124,7 +124,7 @@ describe('spaces_reader fetcher', () => {
['lucene query with geo point query', {
query: {
q: '(foo:bar)',
size: 150,
size: 100,
geo_point: '52.3456,79.6784',
geo_distance: '200km'
},
Expand All @@ -144,7 +144,7 @@ describe('spaces_reader fetcher', () => {
['lucene query with geo bounding box query', {
query: {
q: '(foo:bar)',
size: 1500,
size: 100000,
geo_box_top_left: '34.5234,79.42345',
geo_box_bottom_right: '54.5234,80.3456',
geo_sort_point: '52.3456,79.6784'
Expand All @@ -159,9 +159,7 @@ describe('spaces_reader fetcher', () => {
geo_box_bottom_right: '54.5234,80.3456',
geo_sort_point: '52.3456,79.6784',
},
msg: {
count: 1000
}
msg: {}
}],

])('when performing a %s', (m, { query, opConfig: _opConfig, msg }) => {
Expand All @@ -185,6 +183,9 @@ describe('spaces_reader fetcher', () => {
]
}), { clients });

// query size are overridden for unbounded fetches
query.size = maxSize;

let results: DataEntity[];

beforeEach(async () => {
Expand All @@ -204,7 +205,6 @@ describe('spaces_reader fetcher', () => {
});

await harness.initialize();
// FIXME: is msg ... a slice?
results = await harness.runSlice(msg);
});

Expand Down Expand Up @@ -257,7 +257,7 @@ describe('spaces_reader fetcher', () => {

scope.post(`/${testIndex}?token=${token}`, {
q: '(test:query)',
size: 7500,
size: 100000,
})
.delay(500)
.reply(200, {
Expand Down

0 comments on commit 8415873

Please sign in to comment.