# TermFilter and Array-Fields - bug or intended behaviour

**URL:** <https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074>\
**Category:** Elasticsearch\
**Created:** [March 10, 2011, 1:33pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074 "2011-03-10T13:33:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_B](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@K\_B](https://discuss.elastic.co/u/K_B)\
**Post date:** [March 10, 2011, 1:33pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/1 "2011-03-10T13:33:33Z")

</div>

Hello,

I if one has an ArrayField like

field = ["Val1","Val2","Val3"]

and its not\_analyzed by mapping then in case a Filter is tried to be  
put over it:

FilterBuilders.termFilter("field", "Val1");

the resulting query the flter is put to will allways have 0 results.

Is this intended or a bug?

Best

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 10, 2011, 1:46pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/2 "2011-03-10T13:46:50Z")

</div>

This filter will work. Have you called refresh before you executed the search and after you indexed the document? If it still does not work, gist a curl recreation ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).  
On Thursday, March 10, 2011 at 3:33 PM, K.B. wrote:

> Hello,
> 
> I if one has an ArrayField like
> 
> field = ["Val1","Val2","Val3"]
> 
> and its not\_analyzed by mapping then in case a Filter is tried to be  
> put over it:
> 
> FilterBuilders.termFilter("field", "Val1");
> 
> the resulting query the flter is put to will allways have 0 results.
> 
> Is this intended or a bug?
> 
> Best

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 10, 2011, 1:51pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/3 "2011-03-10T13:51:58Z")

</div>

Hi KB

> I if one has an ArrayField like
> 
> field = ["Val1","Val2","Val3"]
> 
> and its not\_analyzed by mapping then in case a Filter is tried to be  
> put over it:
> 
> FilterBuilders.termFilter("field", "Val1");
> 
> the resulting query the flter is put to will allways have 0 results.

I'm not seeing this. My example shows the correct behaviour:

> <https://gist.github.com/clintongormley/864115>

Are you sure that your field is mapped as not\_analyzed?

Try retrieving the mapping from Elasticsearch and see what it thinks the  
mapping is.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Clint

---

<div class="post-metadata">

**Author:** ![K\_B](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@K\_B](https://discuss.elastic.co/u/K_B)\
**Post date:** [March 10, 2011, 2:46pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/4 "2011-03-10T14:46:43Z")

</div>

Hello,

mapping seems correct, ES tells me:

...  
linie\_mv: {  
\* index: not\_analyzed  
\* type: string  
}  
...

as expected (field is called differently here); As all other requests  
to these fields work, I expect it to be indexed 🙂

see gist:

> <https://gist.github.com/kbachl/b373610376324745ce3c>

If you do a queryString query and add a filter to the builder it will  
give you empty returns;

On 10 Mrz., 14:51, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> Hi KB
> 
> > I if one has an ArrayField like
> 
> > field = ["Val1","Val2","Val3"]
> 
> > and its not\_analyzed by mapping then in case a Filter is tried to be  
> > put over it:
> 
> > FilterBuilders.termFilter("field", "Val1");
> 
> > the resulting query the flter is put to will allways have 0 results.
> 
> I'm not seeing this. My example shows the correct behaviour:
> 
> [ElasticSearch - not\_analyzed array · GitHub](https://gist.github.com/864115)
> 
> Are you sure that your field is mapped as not\_analyzed?
> 
> Try retrieving the mapping from Elasticsearch and see what it thinks the  
> mapping is.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-get-ma)...
> 
> Clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 10, 2011, 2:59pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/5 "2011-03-10T14:59:48Z")

</div>

Hiya

> as expected (field is called differently here); As all other requests  
> to these fields work, I expect it to be indexed 🙂
> 
> see gist:
> 
> [Query is ok but will return null! · GitHub](https://gist.github.com/b373610376324745ce3c)
> 
> If you do a queryString query and add a filter to the builder it will  
> give you empty returns;

I've updated my example to show your same query with a query string, and  
that it does work:

> <https://gist.github.com/clintongormley/864115>

I think your data is not what you think it is.

If you try to recreate this problem from scratch, I think you will find  
where your issue is (or failing that, that it now works 🙂

hth

clint

---

<div class="post-metadata">

**Author:** ![K\_B](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@K\_B](https://discuss.elastic.co/u/K_B)\
**Post date:** [March 10, 2011, 3:08pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/6 "2011-03-10T15:08:55Z")

</div>

heya clint,

thanks for answer but you're cheating 😉

You do:

{  
"query" : {  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "\*"  
}  
},  
"filter" : {  
"term" : {  
"field" : "Val1"  
}  
}  
}  
}  
}

While my java ends up in:

{  
"filtered":{  
"query":{  
"query\_string":{  
"query":"\*"  
}  
},  
"filter":{  
"term":{  
"field":"Val1"  
}  
}  
}  
}

see, you put a big query around your 2 queries, while the java  
transformates to the thing shown below - and that gives null back in  
elasticsearch-head and gives no error as valid JSON;

My data seems ok as it works with either your JSON code or if I put it  
into the first querystring;

Best

On 10 Mrz., 15:59, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> Hiya
> 
> > as expected (field is called differently here); As all other requests  
> > to these fields work, I expect it to be indexed 🙂
> 
> > see gist:
> 
> > [Query is ok but will return null! · GitHub](https://gist.github.com/b373610376324745ce3c)
> 
> > If you do a queryString query and add a filter to the builder it will  
> > give you empty returns;
> 
> I've updated my example to show your same query with a query string, and  
> that it does work:
> 
> [ElasticSearch - not\_analyzed array · GitHub](https://gist.github.com/864115)
> 
> I think your data is not what you think it is.
> 
> If you try to recreate this problem from scratch, I think you will find  
> where your issue is (or failing that, that it now works 🙂
> 
> hth
> 
> clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 10, 2011, 3:23pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/7 "2011-03-10T15:23:59Z")

</div>

Hi KB

> thanks for answer but you're cheating 😉

> see, you put a big query around your 2 queries, while the java  
> transformates to the thing shown below - and that gives null back in  
> elasticsearch-head and gives no error as valid JSON;

I'm not cheating 🙂 That is the correct syntax when using the HTTP API:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Whatever query you pass in needs to be passed as the value of the  
'query' parameter. You can't pass a 'filtered' query as a top level  
param.

Note: there was an incorrect example of a filtered query on

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

which I have now fixed.

clint

---

<div class="post-metadata">

**Author:** ![K\_B](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@K\_B](https://discuss.elastic.co/u/K_B)\
**Post date:** [March 10, 2011, 3:42pm UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/8 "2011-03-10T15:42:43Z")

</div>

Ah, ok,

now thats different then.... ok, the JSON now seems ok and - please  
dont ask me why - my java also now works.... haven't changed a line,  
just an appserver restart...

Thank you very much for your help,

Best

On 10 Mrz., 16:23, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> Hi KB
> 
> > thanks for answer but you're cheating 😉
> 
> > see, you put a big query around your 2 queries, while the java  
> > transformates to the thing shown below - and that gives null back in  
> > elasticsearch-head and gives no error as valid JSON;
> 
> I'm not cheating 🙂 That is the correct syntax when using the HTTP API:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/query.html)
> 
> Whatever query you pass in needs to be passed as the value of the  
> 'query' parameter. You can't pass a 'filtered' query as a top level  
> param.
> 
> Note: there was an incorrect example of a filtered query onhttp://www.elasticsearch.org/guide/reference/api/search/  
> which I have now fixed.
> 
> clint

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:10am UTC](https://discuss.elastic.co/t/termfilter-and-array-fields-bug-or-intended-behaviour/4074/9 "2017-07-06T04:10:21Z")

</div>


