i..e, is there a difference if I put the filter and query together
inside a "filtered" query, OR, if i put them separately like Case 2
(i.e., a "query", and a "filter"). Are there any performance gains in
either of the two ?
Note: In my case I also want to get facets on a particular field, and
use exactly same filters (as my query) for facets as well (does that
make either of the two cases more desirable). Currently I am doing
something like this:
{
"query": {
"term": {
"dept": "engineering"
}
},
"filter": {
"prefix": {
"name": "blah"
}
}
facets": {
"type_facet": {
"terms": {
"field": "type",
"size": 100
},
"facet_filter": {
// Basically I repeat the exact same filter (at top
level) here as well.
"prefix": {
"name": "blah"
}
}
}
}
}
Is this the optimal way to do it ? Is there a better way then to
repeat the filter at N+1 places in query for N facets, i.e., 1 for top-
level query and N for facet_filter for each facet. Will using
'filtered" help me somehow in performance ?
Its explained here: Elasticsearch Platform — Find real-time answers at scale | Elastic. The
idea of the search filter is the filter documents from the result, but not
affect the facets. Facets run on the "query" element, further filtered with
an optional facet_filter.
In your case, if you place the filter in a filtered query within the
"query" element, "everything" will be filtered by it, facets and hits.
i..e, is there a difference if I put the filter and query together
inside a "filtered" query, OR, if i put them separately like Case 2
(i.e., a "query", and a "filter"). Are there any performance gains in
either of the two ?
Note: In my case I also want to get facets on a particular field, and
use exactly same filters (as my query) for facets as well (does that
make either of the two cases more desirable). Currently I am doing
something like this:
{
"query": {
"term": {
"dept": "engineering"
}
},
"filter": {
"prefix": {
"name": "blah"
}
}
facets": {
"type_facet": {
"terms": {
"field": "type",
"size": 100
},
"facet_filter": {
// Basically I repeat the exact same filter (at top
level) here as well.
"prefix": {
"name": "blah"
}
}
}
}
}
Is this the optimal way to do it ? Is there a better way then to
repeat the filter at N+1 places in query for N facets, i.e., 1 for top-
level query and N for facet_filter for each facet. Will using
'filtered" help me somehow in performance ?
Its explained here:Elasticsearch Platform — Find real-time answers at scale | Elastic. The
idea of the search filter is the filter documents from the result, but not
affect the facets. Facets run on the "query" element, further filtered with
an optional facet_filter.
In your case, if you place the filter in a filtered query within the
"query" element, "everything" will be filtered by it, facets and hits.
i..e, is there a difference if I put the filter and query together
inside a "filtered" query, OR, if i put them separately like Case 2
(i.e., a "query", and a "filter"). Are there any performance gains in
either of the two ?
Note: In my case I also want to get facets on a particular field, and
use exactly same filters (as my query) for facets as well (does that
make either of the two cases more desirable). Currently I am doing
something like this:
{
"query": {
"term": {
"dept": "engineering"
}
},
"filter": {
"prefix": {
"name": "blah"
}
}
facets": {
"type_facet": {
"terms": {
"field": "type",
"size": 100
},
"facet_filter": {
// Basically I repeat the exact same filter (at top
level) here as well.
"prefix": {
"name": "blah"
}
}
}
}
}
Is this the optimal way to do it ? Is there a better way then to
repeat the filter at N+1 places in query for N facets, i.e., 1 for top-
level query and N for facet_filter for each facet. Will using
'filtered" help me somehow in performance ?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.