Re: Filter a query without a term

I can think of two possible solutions, both requiring you to change
the JSON format if there is no query provided (no graceful syntax
change).

One solution is the match_all query, which can be followed up by your
filter: Elasticsearch Platform — Find real-time answers at scale | Elastic

Another solution would be to use a constant score query, which always
wraps around a filter: Elasticsearch Platform — Find real-time answers at scale | Elastic

I do not know the performance implications of either query, but I
would assume the latter solution is better since there is no scoring
involved.

Ivan

On Mar 14, 8:07 pm, Rob Faraj rfa...@gmail.com wrote:

I'm still relatively new to Elasticsearch and can't seem to figure out
if I'm doing this correctly. I am trying to produce a query that
searches for a given string. In addition to this query I also want to
filter the results off of an integer field in the document. I am using
the request below and its working...

curl -XPOST 'http://localhost:9200/index/type/_search?
pretty=true&fields=_id,item_id' -d '
{
"query" : {
"query_string" : {
"query" : "foobar"
}
},
"filter" : {
"query" : {
"field": {
"status_id" : "1"
}
}
}}

'

Sometimes there is no term provided, but I would still like to filter
the results. I have substituted the term (foobar) for "*" which I
guess matches everything. Is this a good approach for what I'm trying
to accomplish?

Thanks in advance.