Skip to content

Commit

Permalink
Implicitly update input maps defined on non-expanded queries (common …
Browse files Browse the repository at this point in the history
…cases) (#632)

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
  • Loading branch information
ohltyler authored Feb 19, 2025
1 parent 26f6eae commit 8c0df10
Show file tree
Hide file tree
Showing 3 changed files with 317 additions and 18 deletions.
133 changes: 125 additions & 8 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,27 +301,108 @@ export const VECTOR_TEMPLATE_PLACEHOLDER = `\$\{${VECTOR}\}`;
export const DEFAULT_K = 10;
export const DEFAULT_FETCH_SIZE = 10;

export const FETCH_ALL_QUERY = {
// term-level queries
export const TERM_QUERY_TEXT = {
query: {
match_all: {},
term: {
[TEXT_FIELD_PATTERN]: {
value: QUERY_TEXT_PATTERN,
},
},
},
size: DEFAULT_FETCH_SIZE,
};
export const FETCH_ALL_QUERY_LARGE = {
export const EXISTS_QUERY_TEXT = {
query: {
match_all: {},
exists: {
field: TEXT_FIELD_PATTERN,
},
},
size: 1000,
};
export const TERM_QUERY_TEXT = {
export const FUZZY_QUERY_TEXT = {
query: {
term: {
fuzzy: {
[TEXT_FIELD_PATTERN]: {
value: QUERY_TEXT_PATTERN,
},
},
},
};
export const WILDCARD_QUERY_TEXT = {
query: {
wildcard: {
[TEXT_FIELD_PATTERN]: {
wildcard: QUERY_TEXT_PATTERN,
case_insensitive: false,
},
},
},
};
export const PREFIX_QUERY_TEXT = {
query: {
prefix: {
[TEXT_FIELD_PATTERN]: {
value: QUERY_TEXT_PATTERN,
},
},
},
};
// full-text queries
export const MATCH_QUERY_TEXT = {
query: {
match: {
[TEXT_FIELD_PATTERN]: {
query: QUERY_TEXT_PATTERN,
},
},
},
};
export const MATCH_BOOLEAN_QUERY_TEXT = {
query: {
match_bool_prefix: {
[TEXT_FIELD_PATTERN]: {
query: QUERY_TEXT_PATTERN,
},
},
},
};
export const MATCH_PHRASE_QUERY_TEXT = {
query: {
match_phrase: {
[TEXT_FIELD_PATTERN]: {
query: QUERY_TEXT_PATTERN,
},
},
},
};
export const MATCH_PHRASE_PREFIX_QUERY_TEXT = {
query: {
match_phrase_prefix: {
[TEXT_FIELD_PATTERN]: {
query: QUERY_TEXT_PATTERN,
},
},
},
};
export const QUERY_STRING_QUERY_TEXT = {
query: {
query_string: {
query: QUERY_TEXT_PATTERN,
},
},
};
// misc / other queries
export const FETCH_ALL_QUERY = {
query: {
match_all: {},
},
size: DEFAULT_FETCH_SIZE,
};
export const FETCH_ALL_QUERY_LARGE = {
query: {
match_all: {},
},
size: 1000,
};
export const KNN_QUERY = {
_source: {
excludes: [VECTOR_FIELD_PATTERN],
Expand Down Expand Up @@ -471,6 +552,42 @@ export const QUERY_PRESETS = [
name: 'Term',
query: customStringify(TERM_QUERY_TEXT),
},
{
name: 'Match',
query: customStringify(MATCH_QUERY_TEXT),
},
{
name: 'Exists',
query: customStringify(EXISTS_QUERY_TEXT),
},
{
name: 'Fuzzy',
query: customStringify(FUZZY_QUERY_TEXT),
},
{
name: 'Wildcard',
query: customStringify(WILDCARD_QUERY_TEXT),
},
{
name: 'Prefix',
query: customStringify(PREFIX_QUERY_TEXT),
},
{
name: 'Match boolean',
query: customStringify(MATCH_BOOLEAN_QUERY_TEXT),
},
{
name: 'Match phrase',
query: customStringify(MATCH_PHRASE_QUERY_TEXT),
},
{
name: 'Match phrase prefix',
query: customStringify(MATCH_PHRASE_PREFIX_QUERY_TEXT),
},
{
name: 'Query string',
query: customStringify(QUERY_STRING_QUERY_TEXT),
},
{
name: 'Basic k-NN',
query: customStringify(KNN_QUERY),
Expand Down
119 changes: 119 additions & 0 deletions public/utils/config_to_template_utils.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import '@testing-library/jest-dom';
import { updatePathForExpandedQuery } from './config_to_template_utils';

describe('config_to_template_utils', () => {
beforeEach(() => {});
describe('updatePathForExpandedQuery', () => {
test('term query', () => {
expect(
updatePathForExpandedQuery('query.term.a') === 'query.term.a.value'
);
expect(
updatePathForExpandedQuery('query.term.a.value') ===
'query.term.a.value'
);
expect(
updatePathForExpandedQuery('$.query.term.a') === '$.query.term.a.value'
);
expect(
updatePathForExpandedQuery('a.b.c.d.query.term.a') ===
'a.b.c.d.query.term.a.value'
);
expect(
updatePathForExpandedQuery('query.bool.must[0].term.a') ===
'query.bool.must[0].term.a.value'
);
});
test('prefix query', () => {
expect(
updatePathForExpandedQuery('query.prefix.a') === 'query.prefix.a.value'
);
expect(
updatePathForExpandedQuery('query.prefix.a.value') ===
'query.prefix.a.value'
);
});
test('fuzzy query', () => {
expect(
updatePathForExpandedQuery('query.fuzzy.a') === 'query.fuzzy.a.value'
);
expect(
updatePathForExpandedQuery('query.fuzzy.a.value') ===
'query.fuzzy.a.value'
);
});
test('wildcard query', () => {
expect(
updatePathForExpandedQuery('query.wildcard.a') ===
'query.wildcard.a.wildcard'
);
expect(
updatePathForExpandedQuery('query.wildcard.a.wildcard') ===
'query.wildcard.a.wildcard'
);
});
test('regexp query', () => {
expect(
updatePathForExpandedQuery('query.regexp.a') === 'query.regexp.a.value'
);
expect(
updatePathForExpandedQuery('query.regexp.a.value') ===
'query.regexp.a.value'
);
});
test('match query', () => {
expect(
updatePathForExpandedQuery('query.match.a') === 'query.match.a.query'
);
expect(
updatePathForExpandedQuery('query.match.a.query') ===
'query.match.a.query'
);
});
test('match bool prefix query', () => {
expect(
updatePathForExpandedQuery('query.match_bool_prefix.a') ===
'query.match_bool_prefix.a.query'
);
expect(
updatePathForExpandedQuery('query.match_bool_prefix.a.query') ===
'query.match_bool_prefix.a.query'
);
});
test('match phrase query', () => {
expect(
updatePathForExpandedQuery('query.match_phrase.a') ===
'query.match_phrase.a.query'
);
expect(
updatePathForExpandedQuery('query.match_phrase.a.query') ===
'query.match_phrase.a.query'
);
});
test('match phrase prefix query', () => {
expect(
updatePathForExpandedQuery('query.match_phrase_prefix.a') ===
'query.match_phrase_prefix.a.query'
);
expect(
updatePathForExpandedQuery('query.match_phrase_prefix.a.query') ===
'query.match_phrase_prefix.a.query'
);
});
test('aggs query', () => {
expect(
updatePathForExpandedQuery('aggs.avg_a.avg.field') ===
'aggregations.avg_a.avg.field'
);
expect(
updatePathForExpandedQuery('aggs.b.c.d.aggs.avg_a.avg.field') ===
'aggregations.b.c.d.aggregations.avg_a.avg.field'
);
});
});
});
Loading

0 comments on commit 8c0df10

Please sign in to comment.