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
6 changes: 6 additions & 0 deletions docs/changelog/135776.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 135776
summary: Fix KQL case-sensitivity for keyword fields in ES|QL
area: Search
type: bug
issues:
- 135772
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class KqlQueryBuilder extends AbstractQueryBuilder<KqlQueryBuilder> {
}

private final String query;
private boolean caseInsensitive = true;
private boolean caseInsensitive = false;
private ZoneId timeZone;
private String defaultField;

Expand Down Expand Up @@ -152,7 +152,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected QueryBuilder doIndexMetadataRewrite(QueryRewriteContext context) throws IOException {
protected QueryBuilder doIndexMetadataRewrite(QueryRewriteContext context) {
try {
KqlParser parser = new KqlParser();
QueryBuilder rewrittenQuery = parser.parseKqlQuery(query, createKqlParserContext(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void testCaseInsensitiveWildcardQuery() throws IOException {
for (boolean caseInsensitive : List.of(true, false)) {
KqlQueryBuilder kqlQuery = new KqlQueryBuilder(KEYWORD_FIELD_NAME + ": foo*");
// Check case case_insensitive is true by default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check case case_insensitive is true by default
// Check case case_insensitive is false by default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check case case_insensitive is true by default
// Check case case_insensitive is false by default

assertThat(kqlQuery.caseInsensitive(), equalTo(true));
assertThat(kqlQuery.caseInsensitive(), equalTo(false));

kqlQuery.caseInsensitive(caseInsensitive);

Expand All @@ -190,7 +190,7 @@ public void testCaseInsensitiveTermQuery() throws IOException {
for (boolean caseInsensitive : List.of(true, false)) {
KqlQueryBuilder kqlQuery = new KqlQueryBuilder(KEYWORD_FIELD_NAME + ": foo");
// Check case case_insensitive is true by default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check case case_insensitive is true by default
// Check case case_insensitive is false by default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check case case_insensitive is true by default
// Check case case_insensitive is false by default

assertThat(kqlQuery.caseInsensitive(), equalTo(true));
assertThat(kqlQuery.caseInsensitive(), equalTo(false));

kqlQuery.caseInsensitive(caseInsensitive);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ setup:
- match: { hits.total: 1 }
- match: { hits.hits.0._id: "doc-1" }

- do:
search:
index: test-index
rest_total_hits_as_int: true
body: >
{
"query": { "kql": { "query": "text_field: Bar" } }
}
- match: { hits.total: 1 }
- match: { hits.hits.0._id: "doc-1" }

- do:
search:
index: test-index
Expand Down Expand Up @@ -93,6 +104,16 @@ setup:
- match: { hits.total: 1 }
- match: { hits.hits.0._id: "doc-1" }

- do:
search:
index: test-index
rest_total_hits_as_int: true
body: >
{
"query": { "kql": { "query": "text_field: Bar*" } }
}
- match: { hits.total: 1 }
- match: { hits.hits.0._id: "doc-1" }

---
"KQL match term queries (integer field)":
Expand Down Expand Up @@ -184,6 +205,16 @@ setup:
- match: { hits.total: 1 }
- match: { hits.hits.0._id: "doc-1" }

- do:
search:
index: test-index
rest_total_hits_as_int: true
body: >
{
"query": { "kql": { "query": "keyword_field: Foo bar" } }
}
- match: { hits.total: 0 }

- do:
search:
index: test-index
Expand All @@ -205,6 +236,15 @@ setup:
}
- match: { hits.total: 2 }

- do:
search:
index: test-index
rest_total_hits_as_int: true
body: >
{
"query": { "kql": { "query": "keyword_field: Foo ba*" } }
}
- match: { hits.total: 0 }

---
"KQL match term queries (date field)":
Expand Down