my data contains only keywords or numbers. no full-text fields. My search queries should support: exact match and contains queries.
My question is: If I don't care about the score, and it's always a question of YES or NO, can I always use Filter bool query instead of must bool query in order to create AND condition in order to improve performance?
for example:
query = ( myId=12345 AND sream="aaa" AND name contains "ABC")
GET indexName/_search
{
"query":
{
"bool":
{
"filter":
[
{
"term": {
"myId": {
"value": "12345",
"boost": 1
}
}
},
{
"term": {
"stream": {
"value": "aaa",
"boost": 1
}
}
},
{
"wildcard" : {
"name" : {
"wildcard" : "*abc*",
"boost" : 1.0
}
}
}
]
}
},
"sort" : [
{"_instance" : {"order" : "asc"}}
]
}
Yes, you nailed it! If you're only interested in exact searches, you're not doing any full-text search, and hence, are not interested in scoring, bool/filter
is the way to go!!
Just note, however, that your wildcard
query with a leading wildcard will kill the performance. Depending on how much data you're running this query on, it might be to an extent that filter vs must will make no difference at all. You should consider doing it differently.