Reputation: 4217
I have this query that returns me the customers who have age=40, do not have live in state "ID" and have balance>=20000 and balance<=30000?
The query looks like:
POST /bank/_search?pretty
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
],
"filter": {
"range": {
"balance": {
"gte": 20000,
"lte": 30000
}
}
}
}
}
}
I feel all the result documents are equally relevant but elasticsearch has assigned different score to each document. Sample result: https://jsonblob.com/57de6b37e4b0dc55a4f67d54
I know that score is coming because i am using "match" query. Can anyone tell:-
Is it possible to execute this query avoiding "match" and using only filters? Since i think by putting age=40 and state="ID", I am just filtering the result set.
Can we avoid this score computation since this is unnecessary for above query in our scenario?
Why do these documents have different score. Since query seems to be very simple to me which should return either document matches this query or does not match. There is nothing like match closely or match slightly here.
Upvotes: 2
Views: 122
Reputation: 7472
If you don't care about relevancy and would like to avoid the score computation, you can switch to filters:
POST /bank/_search?pretty
{
"query": {
"bool": {
"filter": [
{
"range": {
"balance": {
"gte": 20000,
"lte": 30000
}
}
},
{
"term": {
"age": "40"
}
},
{
"not": {
"term": {
"state": "ID"
}
}
}
]
}
}
}
If you'd like to know why certain results got a certain score, you can add explain: true
above the query part and get a per-result breakdown of the score.
Upvotes: 1