Exists filter

I'm trying to run a query that looks sort of like this:

{
"filter": {
"term": {
"b_id": "6"
},
"constant_score": {
"filter": {
"exists": {
"field": "rear_placement"
}
}
}
},
"fields": [
"rear_placement",
"price",
"controller",
"name",
"short_name",
"nm"
],
"sort": [
"rear_placement"
]
}

When I add the "constant score" bit the "fields" do not return. Only
_source. Removing the constant score exists bit, the six fields above
return without issue.

It isn't the end of the world for me to return the entire document in this
case, I was just wondering what the deal is with this and if there is
something I'm doing wrong.

James

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a06d4480-16bb-426e-b97a-467b2cd5bf9f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

You would need to combine your two filters with a bool filter:

The constant score query should be at the top level and the exists/term
filters should be combined with a bool filter underneath it. The constant
score wrapper is not really necessary since your filters are not doing any
scoring, so you can just skip it and use the bool filter.

Something like (not tested!)

POST phrase/test/_search
{
"filter": {
"bool": {
"must": [
{
"term": {
"b_id": "6"
}
},
{
"exists": {
"field": "rear_placement"
}
}
]
}
},
"fields": [
"rear_placement",
"price",
"controller",
"name",
"short_name",
"nm"
],
"sort": [
"rear_placement"
]
}

Cheers,

Ivan

On Tue, Jan 14, 2014 at 4:48 AM, James Reynolds eire1130@gmail.com wrote:

I'm trying to run a query that looks sort of like this:

{
"filter": {
"term": {
"b_id": "6"
},
"constant_score": {
"filter": {
"exists": {
"field": "rear_placement"
}
}
}
},
"fields": [
"rear_placement",
"price",
"controller",
"name",
"short_name",
"nm"
],
"sort": [
"rear_placement"
]
}

When I add the "constant score" bit the "fields" do not return. Only
_source. Removing the constant score exists bit, the six fields above
return without issue.

It isn't the end of the world for me to return the entire document in this
case, I was just wondering what the deal is with this and if there is
something I'm doing wrong.

James

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/a06d4480-16bb-426e-b97a-467b2cd5bf9f%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDdx_i0WALXGNhFaUsQjsPzUuNERbJMtwW7uztSXVOuCw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.