Skip to content

Commit

Permalink
Adding yml test for keyword fields with doc_values enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Oct 16, 2023
1 parent 4e0d25e commit c819524
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
"search on keyword fields with doc_values enabled":
- do:
indices.create:
index: test
body:
mappings:
properties:
"some_keyword":
type: "keyword"
index: true
doc_values: true

- do:
bulk:
index: test
refresh: true
body:
- '{"index": {"_index": "test", "_id": "1" }}'
- '{ "some_keyword": "ingesting some random keyword data" }'
- '{ "index": { "_index": "test", "_id": "2" }}'
- '{ "some_keyword": "400" }'
- '{ "index": { "_index": "test", "_id": "3" } }'
- '{ "some_keyword": "5" }'

- do:
search:
index: test
body:
query:
prefix:
some_keyword: "ing"

- match: { hits.hits.0._source.some_keyword: "ingesting some random keyword data" }

- do:
search:
index: test
body:
query:
range: {
"some_keyword": {
"lt": 500
} }

- match: { hits.total.value: 2 }
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.search.TermInSetQuery;
Expand Down Expand Up @@ -433,7 +434,13 @@ public Query prefixQuery(
return new IndexOrDocValuesQuery(indexQuery, dvQuery);
}
if (hasDocValues()) {
return super.prefixQuery(value, MultiTermQuery.DOC_VALUES_REWRITE, caseInsensitive, context);
if (caseInsensitive) {
return AutomatonQueries.caseInsensitivePrefixQuery(
(new Term(name(), indexedValueForSearch(value))),
MultiTermQuery.DOC_VALUES_REWRITE
);
}
return new PrefixQuery(new Term(name(), indexedValueForSearch(value)), MultiTermQuery.DOC_VALUES_REWRITE);
}
return super.prefixQuery(value, method, caseInsensitive, context);
}
Expand Down

0 comments on commit c819524

Please sign in to comment.