Skip to content

Commit

Permalink
TermsEnum api - allow null search strings (#73144)
Browse files Browse the repository at this point in the history
Allow null search strings (matches all)

Closes #73141
  • Loading branch information
markharwood authored May 17, 2021
1 parent 7b64cae commit dbc37f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions docs/reference/search/terms-enum.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ Which field to match

[[terms-enum-string-param]]
`string`::
(Mandatory, string)
The string to match at the start of indexed terms
(Optional, string)
The string to match at the start of indexed terms. If not provided, all terms in the field
are considered.

[[terms-enum-size-param]]
`size`::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ public String toString() {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field("field", field);
builder.field("string", string);
if (string != null) {
builder.field("string", string);
}
if (searchAfter != null) {
builder.field("search_after", searchAfter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ protected NodeTermsEnumResponse dataNodeOperation(NodeTermsEnumRequest request,
if (mappedFieldType != null) {
TermsEnum terms = mappedFieldType.getTerms(
request.caseInsensitive(),
request.string(),
request.string() == null ? "" : request.string(),
queryShardContext,
request.searchAfter()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ teardown:
- length: {terms: 0}

---
"Test null search string allowed":
- skip:
version: " - 7.99.99"
reason: TODO remove this skip after PR 73144 is backported to 7.x

- do:
terms_enum:
index: test_k
body: {"field": "foo"}
- length: {terms: 1}
---
"Test search after keyword field":
- do:
terms_enum:
Expand Down

0 comments on commit dbc37f9

Please sign in to comment.