Skip to content

Commit

Permalink
Specify the operator option when generating term queries. (#6409)
Browse files Browse the repository at this point in the history
* Specify the operator option when generating term queries.

This restores previous functionality when querying for multi-term values in analysed fields

* Changelog
  • Loading branch information
tobio committed Nov 22, 2022
1 parent 0a2504a commit 9ffddab
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ Object {
"must": Array [
Object {
"match": Object {
"group": "kibana",
"group": Object {
"operator": "and",
"query": "kibana",
},
},
},
Object {
"match": Object {
"group": "logstash",
"group": Object {
"operator": "and",
"query": "logstash",
},
},
},
],
Expand All @@ -33,12 +39,18 @@ Object {
"must": Array [
Object {
"match": Object {
"group": "es",
"group": Object {
"operator": "and",
"query": "es",
},
},
},
Object {
"match": Object {
"group": "beats",
"group": Object {
"operator": "and",
"query": "beats",
},
},
},
],
Expand All @@ -60,7 +72,10 @@ Object {
},
Object {
"match": Object {
"group": "kibana",
"group": Object {
"operator": "and",
"query": "kibana",
},
},
},
Object {
Expand All @@ -87,12 +102,18 @@ Object {
"must": Array [
Object {
"match": Object {
"group": "eng",
"group": Object {
"operator": "and",
"query": "eng",
},
},
},
Object {
"match": Object {
"group": "es",
"group": Object {
"operator": "and",
"query": "es",
},
},
},
],
Expand All @@ -117,7 +138,10 @@ Object {
},
Object {
"match": Object {
"group": "kibana",
"group": Object {
"operator": "and",
"query": "kibana",
},
},
},
],
Expand Down Expand Up @@ -160,7 +184,10 @@ Object {
"should": Array [
Object {
"match": Object {
"group": "eng",
"group": Object {
"operator": "or",
"query": "eng",
},
},
},
Object {
Expand Down Expand Up @@ -197,12 +224,18 @@ Object {
"should": Array [
Object {
"match": Object {
"group": "eng",
"group": Object {
"operator": "or",
"query": "eng",
},
},
},
Object {
"match": Object {
"group": "es",
"group": Object {
"operator": "or",
"query": "es",
},
},
},
],
Expand All @@ -212,7 +245,10 @@ Object {
"must_not": Array [
Object {
"match": Object {
"group": "kibana",
"group": Object {
"operator": "and",
"query": "kibana",
},
},
},
],
Expand All @@ -232,7 +268,10 @@ Object {
"must": Array [
Object {
"match": Object {
"name": "john",
"name": Object {
"operator": "and",
"query": "john",
},
},
},
],
Expand All @@ -243,7 +282,10 @@ Object {
"must": Array [
Object {
"match": Object {
"name": "fred",
"name": Object {
"operator": "and",
"query": "fred",
},
},
},
],
Expand All @@ -269,7 +311,10 @@ Object {
"must": Array [
Object {
"match": Object {
"name": "john",
"name": Object {
"operator": "and",
"query": "john",
},
},
},
],
Expand Down Expand Up @@ -425,7 +470,10 @@ Object {
"must": Array [
Object {
"match": Object {
"name": "john",
"name": Object {
"operator": "and",
"query": "john",
},
},
},
],
Expand Down
13 changes: 11 additions & 2 deletions src/components/search_bar/query/ast_to_es_query_dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,21 @@ export const _fieldValuesToQuery = (
queries.push({
bool: {
[andOr === 'and' ? 'must' : 'should']: [
...terms.map((value) => ({ match: { [field]: value } })),
...terms.map((value) => ({
match: {
[field]: {
query: value,
operator: andOr,
},
},
})),
],
},
});
} else if (terms.length === 1) {
queries.push({ match: { [field]: terms[0] } });
queries.push({
match: { [field]: { query: terms[0], operator: andOr } },
});
}

if (phrases.length > 0) {
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6409.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Restores the previous match operator behaviour when the query value is split into multiple terms after analysis.

0 comments on commit 9ffddab

Please sign in to comment.