Filtering on Script Value


(brian) #1

I'm trying to calculate a value for each hit then select or filter on a
calculated value. Something like below:

"query": {
    "match_all": {}
    },
    "script_fields" : {
        "counter" : {
            "script" : "count++",
            "params" : {
                "count"  : 1
            }
        },
        "source" : {
          "script" : "_source"
    }
  }

I'd like to filter on the count parameter.

I've read on a StackOverflow post that you cannot filter on a script value.

So is there another way to calculate some value dynamically and filter on
that value?

If not, is there a nested SQL SELECT equivalent in ElasticSearch? Maybe I
could execute the first query to calculate the 'count' then execute another
query to filter by a value?

--
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/8206ea84-b314-4b8e-8f3c-248d9f5a99e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Cédric Hourcade) #2

Hello,

You should be able to filter with a script using the script filter:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html

Cédric Hourcade
ced@wal.fr

On Wed, Jun 25, 2014 at 4:36 AM, Brian Behling brian.behling@gmail.com wrote:

I'm trying to calculate a value for each hit then select or filter on a
calculated value. Something like below:

"query": {
    "match_all": {}
    },
    "script_fields" : {
        "counter" : {
            "script" : "count++",
            "params" : {
                "count"  : 1
            }
        },
        "source" : {
          "script" : "_source"
    }
  }

I'd like to filter on the count parameter.

I've read on a StackOverflow post that you cannot filter on a script value.

So is there another way to calculate some value dynamically and filter on
that value?

If not, is there a nested SQL SELECT equivalent in ElasticSearch? Maybe I
could execute the first query to calculate the 'count' then execute another
query to filter by a value?

--
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/8206ea84-b314-4b8e-8f3c-248d9f5a99e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/CAJQxjPPE0dAt%2BoZr%3Dev9SpDwy-04fkWX3xdAmsLcXEL%3D6i6fRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(brian) #3

I've tried that with this query:

GET leases_allv2/_search
{
"query": {
"filtered": {
"filter": {
"and": [
{
"or": [
{
"term": {
"states": "co"
}
}
]
},
{

    "script" : {
        "script" : "count++; count <= 3",
        "params" : {
            "count" : 0
        }
    }
      }
    ]
  }
  
}

}
}

But what happens with that query is since I have 5 shards on our database,
I get 15 results back. So the counter variable is getting reset for each
shard.

Is there a way to keep that counter from resetting when searching each
shard?

On Wednesday, June 25, 2014 12:02:57 AM UTC-6, Cédric Hourcade wrote:

Hello,

You should be able to filter with a script using the script filter:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html

Cédric Hourcade
c...@wal.fr <javascript:>

On Wed, Jun 25, 2014 at 4:36 AM, Brian Behling <brian....@gmail.com
<javascript:>> wrote:

I'm trying to calculate a value for each hit then select or filter on a
calculated value. Something like below:

"query": { 
    "match_all": {} 
    }, 
    "script_fields" : { 
        "counter" : { 
            "script" : "count++", 
            "params" : { 
                "count"  : 1 
            } 
        }, 
        "source" : { 
          "script" : "_source" 
    } 
  } 

I'd like to filter on the count parameter.

I've read on a StackOverflow post that you cannot filter on a script
value.

So is there another way to calculate some value dynamically and filter
on
that value?

If not, is there a nested SQL SELECT equivalent in ElasticSearch? Maybe
I
could execute the first query to calculate the 'count' then execute
another
query to filter by a value?

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/elasticsearch/8206ea84-b314-4b8e-8f3c-248d9f5a99e7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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/def2deb6-9bdc-4fb2-a1ad-b26832a725c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4