Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src-docs/src/views/search_bar/search_bar_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const SearchBarExample = {
(free text words) - Example,
<EuiCode>website -production</EuiCode>. In this example the
intention is to find all items that have the &quot;website&quot;
terms in them but do not have the word &quot;production&quot;
terms in them but do not have the word &quot;production&quot;.
Terms are AND&apos;d together by default.
</li>
<li>
Phrases can be matched by surrounding multiple words with quotes -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ Object {
}
`;

exports[`astToEsQueryDsl ast - '(john OR -mary)' 1`] = `
Object {
"bool": Object {
"must": Array [
Object {
"bool": Object {
"should": Array [
Object {
"bool": Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "+john",
},
},
],
},
},
Object {
"bool": Object {
"must_not": Array [
Object {
"simple_query_string": Object {
"query": "+mary",
},
},
],
},
},
],
},
},
],
},
}
`;

exports[`astToEsQueryDsl ast - '-group:es group:kibana -group:beats group:logstash' 1`] = `
Object {
"bool": Object {
Expand Down Expand Up @@ -67,7 +104,7 @@ Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "john",
"query": "+john",
},
},
Object {
Expand All @@ -94,7 +131,7 @@ Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "john",
"query": "+john",
},
},
Object {
Expand Down Expand Up @@ -133,7 +170,7 @@ Object {
"must_not": Array [
Object {
"simple_query_string": Object {
"query": "doe",
"query": "+doe",
},
},
Object {
Expand All @@ -155,14 +192,14 @@ Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "john",
"query": "+john",
},
},
],
"must_not": Array [
Object {
"simple_query_string": Object {
"query": "sales",
"query": "+sales",
},
},
],
Expand All @@ -176,7 +213,7 @@ Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "john",
"query": "+john",
},
},
Object {
Expand Down Expand Up @@ -216,7 +253,7 @@ Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "john",
"query": "+john",
},
},
Object {
Expand Down Expand Up @@ -498,7 +535,7 @@ Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "Teacher",
"query": "+Teacher",
},
},
],
Expand All @@ -518,14 +555,14 @@ Object {
"must": Array [
Object {
"simple_query_string": Object {
"query": "\\"john smith\\"",
"query": "+\\"john smith\\"",
},
},
],
"must_not": Array [
Object {
"simple_query_string": Object {
"query": "\\"sales team\\"",
"query": "+\\"sales team\\"",
},
},
],
Expand Down
9 changes: 9 additions & 0 deletions src/components/search_bar/query/ast_to_es_query_dsl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ describe('astToEsQueryDsl', () => {
expect(query).toMatchSnapshot();
});

test("ast - '(john OR -mary)'", () => {
const query = astToEsQueryDsl(
AST.create([
AST.Group.must([AST.Term.must('john'), AST.Term.mustNot('mary')]),
])
);
expect(query).toMatchSnapshot();
});

test("ast - '-group:es group:kibana -group:beats group:logstash'", () => {
const query = astToEsQueryDsl(
AST.create([
Expand Down
9 changes: 6 additions & 3 deletions src/components/search_bar/query/ast_to_es_query_dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ const processDateOperation = (value: DateValue, operator?: OperatorType) => {
};

export const _termValuesToQuery = (values: Value[], options: Options) => {
const body: { query: string; fields?: string[] } = {
const body: {
query: string;
fields?: string[];
} = {
query: values
.map((value: Value) => {
if (isString(value) && value.match(/\s/)) {
return `"${value}"`;
return `+"${value}"`;
}
return value;
return `+${value}`;
})
.join(' '),
};
Expand Down
4 changes: 4 additions & 0 deletions upcoming_changelogs/6717.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**Bug fixes**

- Fixed inconsistency in AND/OR semantics between DSL and query string generation by the search bar component.