Filter a filed so that it matches if is has a certain value or if it is empty

How do I do a search so that it matches if a certain parameter is an empty
array or if it has a certain set of values.
I'm trying something like this:

...
"filters": [
{
"script" : {
"script" :
"doc['filed.subfield.all'].values.length == 0"
}
},
{
"and":{
"filters": [
{
"term": {
"filed.subfield.all": 123
}
}
]
}
}
]
...

but it throws the following error:
Query Failed [Failed to execute main query]]; nested:
PropertyAccessException[[Error: could not access: length; in class:
java.util.Collections$EmptyList] [Near : {... doc['"filed.subfield.all'].value
....}] ^ [Line: 1, Column: 1]]; }]

Can anyone get why I'm getting this?

An example data structure (one of the ones I'm trying to get):

{
"data": "123 can",
"subfiled": {
"all":[],
"some":[
123
]
}
}

Another example data structure (one of the ones I'm trying not to get):

{
"data": "123 can",
"subfiled": {
"all":[123,321],
"some":[]
}
}

I didn't give more information because I think you don't require but if you
still require more information, just ask.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi bruno,

You try to use "doc['filed.subfield.all'].empty" instead of "values.length == 0".
See Elasticsearch Platform — Find real-time answers at scale | Elastic

I try to use this query, then i get data that include "all":.

{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"script": {
"script": "doc['subfiled.all'].empty"
}
}
}
}
}


Jun Ohtani
johtani@gmail.com
blog : http://blog.johtani.info
twitter : http://twitter.com/johtani

On 2013/10/11, at 0:08, bruno ais brunoaiss@gmail.com wrote:

How do I do a search so that it matches if a certain parameter is an empty array or if it has a certain set of values.
I'm trying something like this:

...
"filters": [
{
"script" : {
"script" : "doc['filed.subfield.all'].values.length == 0"
}
},
{
"and":{
"filters": [
{
"term": {
"filed.subfield.all": 123
}
}
]
}
}
]
...

but it throws the following error:
Query Failed [Failed to execute main query]]; nested: PropertyAccessException[[Error: could not access: length; in class: java.util.Collections$EmptyList] [Near : {... doc['"filed.subfield.all'].value ....}] ^ [Line: 1, Column: 1]]; }]

Can anyone get why I'm getting this?

An example data structure (one of the ones I'm trying to get):

{
"data": "123 can",
"subfiled": {
"all":,
"some":[
123
]
}
}

Another example data structure (one of the ones I'm trying not to get):

{
"data": "123 can",
"subfiled": {
"all":[123,321],
"some":
}
}

I didn't give more information because I think you don't require but if you still require more information, just ask.

--
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.
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.
For more options, visit https://groups.google.com/groups/opt_out.