Last active
August 29, 2015 14:05
-
-
Save luizgpsantos/a8ea5743cfe96aea478d to your computer and use it in GitHub Desktop.
Otimização de filtros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Query inicial | |
------------------------- | |
POST _search | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"tag": { | |
"value": "elasticsearch" | |
} | |
} | |
}, | |
{ | |
"multi_match": { | |
"query": "query tunning", | |
"fields": [ | |
"title^5", | |
"body" | |
] | |
} | |
} | |
] | |
} | |
} | |
} | |
Otimização errada! O filtro é usado depois da query. Não contribui para aggregation. | |
POST _search | |
{ | |
"query": { | |
"multi_match": { | |
"query": "query tunning", | |
"fields": [ | |
"title^5", | |
"body" | |
] | |
} | |
}, | |
"postfilter": { | |
"term": { | |
"tag": "elasticsearch" | |
} | |
} | |
} | |
Otimização correta. | |
POST _search | |
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"multi_match": { | |
"query": "query tunning", | |
"fields": [ | |
"title^5", | |
"body" | |
] | |
} | |
}, | |
"filter": { | |
"term": { | |
"tag": "elasticsearch" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment