Script fields based on filters

Is it possible to use script fields to add a field to the returned doc
based on which filter matched it in the first place? For example, in
my situation I have something like:

...
"filter": {
"or": [
{ "terms": { field1: [ term1, term2, term2 ] } },
{ "range": { field2: { "from": 0, "to": 100 } }
]
}
...

I'd like to add the result doc to have a field called "foo1" if the
terms filter matched or "foo2" if the range filter matched.

-Andrei

No, its not possible. Not sure what you are after and why not returning both
fields is not an option?

On Thu, Sep 9, 2010 at 8:35 PM, Andrei andrei@zmievski.org wrote:

Is it possible to use script fields to add a field to the returned doc
based on which filter matched it in the first place? For example, in
my situation I have something like:

...
"filter": {
"or": [
{ "terms": { field1: [ term1, term2, term2 ] } },
{ "range": { field2: { "from": 0, "to": 100 } }
]
}
...

I'd like to add the result doc to have a field called "foo1" if the
terms filter matched or "foo2" if the range filter matched.

-Andrei

I misspoke a bit – I want to return a single field, but with the value
of it depending on the which filter matched.

I'm trying to emulate something like SQL's CASE statement, to classify
each document into one of the groups depending on which filter it
matches.

-Andrei

On Sep 9, 1:59 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

No, its not possible. Not sure what you are after and why not returning both
fields is not an option?

mmm, interesting feature. You can't currently do it, but I think I have an
idea of how it can be done. You will need to be able to "name" your filters,
and then, when searching, you can say that for each hit, return all the
named filters it matches. Sounds good?

On Fri, Sep 10, 2010 at 12:02 AM, Andrei andrei@zmievski.org wrote:

I misspoke a bit – I want to return a single field, but with the value
of it depending on the which filter matched.

I'm trying to emulate something like SQL's CASE statement, to classify
each document into one of the groups depending on which filter it
matches.

-Andrei

On Sep 9, 1:59 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

No, its not possible. Not sure what you are after and why not returning
both
fields is not an option?

That sounds great. I assume that I would be able to name only some of
the filters? Also, would I be able to control the name of the field
that will contain matched filters?

-Andrei

On Sep 10, 6:19 am, Shay Banon shay.ba...@elasticsearch.com wrote:

mmm, interesting feature. You can't currently do it, but I think I have an
idea of how it can be done. You will need to be able to "name" your filters,
and then, when searching, you can say that for each hit, return all the
named filters it matches. Sounds good?

Yea, you will only get back filters that you actually named when you defined
them in the search DSL. I was thinking that the name of the field will
always be the same, something like: "matched_filters" : ["filter1",
"filter3].

On Fri, Sep 10, 2010 at 7:04 PM, Andrei andrei@zmievski.org wrote:

That sounds great. I assume that I would be able to name only some of
the filters? Also, would I be able to control the name of the field
that will contain matched filters?

-Andrei

On Sep 10, 6:19 am, Shay Banon shay.ba...@elasticsearch.com wrote:

mmm, interesting feature. You can't currently do it, but I think I have
an
idea of how it can be done. You will need to be able to "name" your
filters,
and then, when searching, you can say that for each hit, return all the
named filters it matches. Sounds good?

Okay, I can do some post-processing on the client end I guess.

On Sep 10, 12:30 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Yea, you will only get back filters that you actually named when you defined
them in the search DSL. I was thinking that the name of the field will
always be the same, something like: "matched_filters" : ["filter1",
"filter3].

yea, giving the option to name the field as well I think it going too far.
Care to open an issue since all of this needs to be implemented at one point
:wink:

On Fri, Sep 10, 2010 at 11:08 PM, Andrei andrei@zmievski.org wrote:

Okay, I can do some post-processing on the client end I guess.

On Sep 10, 12:30 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Yea, you will only get back filters that you actually named when you
defined
them in the search DSL. I was thinking that the name of the field will
always be the same, something like: "matched_filters" : ["filter1",
"filter3].

ok, opened an issue and pushed an implementation for it, I think its a great
idea to have this capability. Here is the issue:
Search API: Allow to name filters and return per hit the filters it matched on · Issue #364 · elastic/elasticsearch · GitHub.

On Fri, Sep 10, 2010 at 11:11 PM, Shay Banon
shay.banon@elasticsearch.comwrote:

yea, giving the option to name the field as well I think it going too far.
Care to open an issue since all of this needs to be implemented at one point
:wink:

On Fri, Sep 10, 2010 at 11:08 PM, Andrei andrei@zmievski.org wrote:

Okay, I can do some post-processing on the client end I guess.

On Sep 10, 12:30 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Yea, you will only get back filters that you actually named when you
defined
them in the search DSL. I was thinking that the name of the field will
always be the same, something like: "matched_filters" : ["filter1",
"filter3].

This is great, thank you! I will test soon and report any issues.

-Andrei

On Sep 11, 2:40 am, Shay Banon shay.ba...@elasticsearch.com wrote:

ok, opened an issue and pushed an implementation for it, I think its a great
idea to have this capability. Here is the issue:Search API: Allow to name filters and return per hit the filters it matched on · Issue #364 · elastic/elasticsearch · GitHub.

On Fri, Sep 10, 2010 at 11:11 PM, Shay Banon
shay.ba...@elasticsearch.comwrote:

yea, giving the option to name the field as well I think it going too far.
Care to open an issue since all of this needs to be implemented at one point
:wink:

On Fri, Sep 10, 2010 at 11:08 PM, Andrei and...@zmievski.org wrote:

Okay, I can do some post-processing on the client end I guess.

On Sep 10, 12:30 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Yea, you will only get back filters that you actually named when you
defined
them in the search DSL. I was thinking that the name of the field will
always be the same, something like: "matched_filters" : ["filter1",
"filter3].