Skip to content

Instantly share code, notes, and snippets.

@luizgpsantos
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizgpsantos/a8ea5743cfe96aea478d to your computer and use it in GitHub Desktop.
Save luizgpsantos/a8ea5743cfe96aea478d to your computer and use it in GitHub Desktop.
Otimização de filtros
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