About Querystring Search
eddyyuen opened this issue · comments
CreateIndex
{ "name": "logs", "storage_type": "disk", "mappings": { "properties": { "lv": { "type": "keyword", "index": true, "sortable": true, "aggregatable": true } } } }
AddDocument
{ "lv":"lv-001" }
{ "lv":"LV001" }
Search /api/logs/_search
{ "search_type":"querystring", "query": { "term":"+lv:LV001" }, "sort_fields": ["-_score"], "from": 0, "max_results": 20, "_source": [] }
{ "search_type":"querystring", "query": { "term":"+lv:lv-001" }, "sort_fields": ["-_score"], "from": 0, "max_results": 20, "_source": [] }
QUESTION
None result hits. WHY?
I can only search using DSL
post /es/logs/_search
{ "query": { "bool": { "filter": [ { "term": { "lv": "LV001" }} ] } } }
Looks like a bug in querystring implementation. I will check this.
Because, with query_string
the query term will analyzer first. default analyzer try to split token and lowerCase.
LV001
after analyzer will become to lv001
lv-001
after analyzer will become to lv 001
but with field type keyword
will do nothing on value, just stored as LV001
or lv-001
.
So, lv001
can't match LV001
, lv-001
can't match lv 001
(there has two tokens).
as you example:
just can use es compatible api to search:
{ "query": { "bool": { "filter": [ { "term": { "lv": "LV001" }} ] } } }
{ "query": { "bool": { "filter": [ { "term": { "lv": "lv-001" }} ] } } }
Next version, you can use new search api do query_string
, i will improve it.