Filters in Query DSL


(Andrew Degtiariov) #1

Hello!

I'm trying to understand how to use filters in queries. For example:

curl -XGET 'http://localhost:9200/contacts/contact/_sea'ch' -d '
{
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : {
"company_id": "4ba0c449fa5bd85769000001"
}
}
}
}

It close to an example from documentation (http://
www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/filtered_query/)
but I'm get an error:
...
Parse Failure [No parser for element [filtered]]

Where am I wrong?


(Clinton Gormley) #2

On Wed, 2010-07-14 at 08:11 -0700, ad wrote:

curl -XGET 'http://localhost:9200/contacts/contact/_sea'ch' -d '
{
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : {
"company_id": "4ba0c449fa5bd85769000001"
}
}
}
}

You're missing "query":

curl -XGET 'http://localhost:9200/contacts/contact/_search' -d '
{
"query": {
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : {
"company_id": "4ba0c449fa5bd85769000001"
}
}
}
}
}

And the same query but somewhat more efficient (apparently):

curl -XGET 'http://localhost:9200/contacts/contact/_search' -d '
{
"query": {
"constant_score" : {
"filter" : {
"term" : {
"company_id": "4ba0c449fa5bd85769000001"
}
}
}
}
}

clint


(Andrew Degtiariov) #3

Oh, thank you!
It's worked :slight_smile:

2010/7/14 Clinton Gormley clinton@iannounce.co.uk:

On Wed, 2010-07-14 at 08:11 -0700, ad wrote:

curl -XGET 'http://localhost:9200/contacts/contact/_sea'ch' -d '
{
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : {
"company_id": "4ba0c449fa5bd85769000001"
}
}
}
}

You're missing "query":

curl -XGET 'http://localhost:9200/contacts/contact/_search' -d '
{
"query": {
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"term" : {
"company_id": "4ba0c449fa5bd85769000001"
}
}
}
}
}

And the same query but somewhat more efficient (apparently):

curl -XGET 'http://localhost:9200/contacts/contact/_search' -d '
{
"query": {
"constant_score" : {
"filter" : {
"term" : {
"company_id": "4ba0c449fa5bd85769000001"
}
}
}
}
}

clint

--
Andrew Degtiariov
DA-RIPE


(system) #4