forked from elastic/elasticsearch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REST: Unify query_string parameters parsing
There currently are small differences between search api and count, exists, validate query, explain api when it comes to reading query_string parameters. `analyze_wildcard`, `lowercase_expanded_terms` and `lenient` are only read by the search api and ignored by all other mentioned apis. Unified code to fix this and make sure it doesn't happen again. Also shared some code when it comes to printing out the query as part of SearchSourceBuilder conversion to ToXContent. Extended REST spec to include all the supported params (some that were already supported weren't listed), and added REST tests (also some basic tests for count and search_exists which weren't tested at all). Closes elastic#11057
- Loading branch information
Showing
14 changed files
with
604 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
"count with body": | ||
- do: | ||
indices.create: | ||
index: test | ||
- do: | ||
index: | ||
index: test | ||
type: test | ||
id: 1 | ||
body: { foo: bar } | ||
|
||
- do: | ||
indices.refresh: | ||
index: [test] | ||
|
||
- do: | ||
count: | ||
index: test | ||
type: test | ||
body: | ||
query: | ||
match: | ||
foo: bar | ||
|
||
- match: {count : 1} | ||
|
||
- do: | ||
count: | ||
index: test | ||
type: test | ||
body: | ||
query: | ||
match: | ||
foo: test | ||
|
||
- match: {count : 0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
"count with query_string parameters": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
mappings: | ||
test: | ||
_all: | ||
enabled: false | ||
properties: | ||
number: | ||
type: integer | ||
|
||
- do: | ||
index: | ||
index: test | ||
type: test | ||
id: 1 | ||
body: { field: foo bar} | ||
|
||
- do: | ||
indices.refresh: | ||
index: [test] | ||
|
||
- do: | ||
count: | ||
index: test | ||
q: bar | ||
df: field | ||
|
||
- match: {count : 1} | ||
|
||
- do: | ||
count: | ||
index: test | ||
q: field:foo field:xyz | ||
|
||
- match: {count : 1} | ||
|
||
- do: | ||
count: | ||
index: test | ||
q: field:foo field:xyz | ||
default_operator: AND | ||
|
||
- match: {count : 0} | ||
|
||
- do: | ||
count: | ||
index: test | ||
q: field:bars | ||
analyzer: snowball | ||
|
||
- match: {count : 1} | ||
|
||
- do: | ||
count: | ||
index: test | ||
q: field:BA* | ||
lowercase_expanded_terms: false | ||
|
||
- match: {count : 0} | ||
|
||
- do: | ||
count: | ||
index: test | ||
q: field:BA* | ||
analyze_wildcard: true | ||
|
||
- match: {count : 1} | ||
|
||
- do: | ||
count: | ||
index: test | ||
q: number:foo | ||
lenient: true | ||
|
||
- match: {count : 0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
"explain with query_string parameters": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
mappings: | ||
test: | ||
_all: | ||
enabled: false | ||
properties: | ||
number: | ||
type: integer | ||
|
||
- do: | ||
index: | ||
index: test | ||
type: test | ||
id: 1 | ||
body: { field: foo bar} | ||
|
||
- do: | ||
indices.refresh: | ||
index: [test] | ||
|
||
- do: | ||
explain: | ||
index: test | ||
type: test | ||
id: 1 | ||
q: bar | ||
df: field | ||
|
||
- is_true: matched | ||
|
||
- do: | ||
explain: | ||
index: test | ||
type: test | ||
id: 1 | ||
q: field:foo field:xyz | ||
|
||
- is_true: matched | ||
|
||
- do: | ||
explain: | ||
index: test | ||
type: test | ||
id: 1 | ||
q: field:foo field:xyz | ||
default_operator: AND | ||
|
||
- is_false: matched | ||
|
||
- do: | ||
explain: | ||
index: test | ||
type: test | ||
id: 1 | ||
q: field:bars | ||
analyzer: snowball | ||
|
||
- is_true: matched | ||
|
||
- do: | ||
explain: | ||
index: test | ||
type: test | ||
id: 1 | ||
q: field:BA* | ||
lowercase_expanded_terms: false | ||
|
||
- is_false: matched | ||
|
||
- do: | ||
explain: | ||
index: test | ||
type: test | ||
id: 1 | ||
q: field:BA* | ||
analyze_wildcard: true | ||
|
||
- is_true: matched | ||
|
||
- do: | ||
explain: | ||
index: test | ||
type: test | ||
id: 1 | ||
q: number:foo | ||
lenient: true | ||
|
||
- is_false: matched |
70 changes: 70 additions & 0 deletions
70
rest-api-spec/test/indices.validate_query/20_query_string.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
"validate_query with query_string parameters": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
mappings: | ||
test: | ||
_all: | ||
enabled: false | ||
properties: | ||
field: | ||
type: string | ||
number: | ||
type: integer | ||
|
||
- do: | ||
indices.validate_query: | ||
index: test | ||
q: bar | ||
df: field | ||
|
||
- is_true: valid | ||
|
||
- do: | ||
indices.validate_query: | ||
index: test | ||
q: field:foo field:xyz | ||
|
||
- is_true: valid | ||
|
||
- do: | ||
indices.validate_query: | ||
index: test | ||
q: field:foo field:xyz | ||
default_operator: AND | ||
|
||
- is_true: valid | ||
|
||
- do: | ||
indices.validate_query: | ||
index: test | ||
q: field:bars | ||
analyzer: snowball | ||
|
||
- is_true: valid | ||
|
||
- do: | ||
indices.validate_query: | ||
index: test | ||
q: field:BA* | ||
lowercase_expanded_terms: false | ||
|
||
- is_true: valid | ||
|
||
- do: | ||
indices.validate_query: | ||
index: test | ||
q: field:BA* | ||
analyze_wildcard: true | ||
|
||
- is_true: valid | ||
|
||
- do: | ||
indices.validate_query: | ||
index: test | ||
q: number:foo | ||
lenient: true | ||
|
||
- is_true: valid |
Oops, something went wrong.