# Term filter for array list not working

**URL:** <https://discuss.elastic.co/t/term-filter-for-array-list-not-working/9028>\
**Category:** Elasticsearch\
**Created:** [September 14, 2012, 9:33pm UTC](https://discuss.elastic.co/t/term-filter-for-array-list-not-working/9028 "2012-09-14T21:33:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [September 14, 2012, 9:33pm UTC](https://discuss.elastic.co/t/term-filter-for-array-list-not-working/9028/1 "2012-09-14T21:33:13Z")

</div>

can someone tell me what i am doing wrong?  
basically i have an index of documents that have a field called "tags". it  
is a list of strings.  
one of the documents has  
"tags" : ["spam"]

but this filter in java is not taking effect -

```
            FilterBuilder noSpamFilter = FilterBuilders.orFilter(
                    FilterBuilders.missingFilter("tags")
                    ,FilterBuilders.notFilter(FilterBuilders.termFilter(
                    "tags", "spam")));

```

when i do a search with this filter, the document with spam tag is still  
being returned. am i using it incorrectly?

thanks

--

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 15, 2012, 1:18pm UTC](https://discuss.elastic.co/t/term-filter-for-array-list-not-working/9028/2 "2012-09-15T13:18:36Z")

</div>

Hi

On Fri, Sep 14, 2012 at 11:33 PM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com) wrote:

> can someone tell me what i am doing wrong?  
> basically i have an index of documents that have a field called "tags". it is a list of strings.  
> one of the documents has  
> "tags" : ["spam"]
> 
> but this filter in java is not taking effect -
> 
> ```
> FilterBuilder noSpamFilter = FilterBuilders.orFilter(
> FilterBuilders.missingFilter("tags")
> ,FilterBuilders.notFilter(FilterBuilders.termFilter(
> "tags", "spam")));
> 
> ```
> 
> when i do a search with this filter, the document with spam tag is still being returned. am i using it incorrectly?

Testing it with ES 0.19.8 works flawlessly for me. You are sure

This is my sample source

```
    FilterBuilder noSpamFilter = FilterBuilders.orFilter(
            FilterBuilders.missingFilter("tags")
            ,FilterBuilders.notFilter(FilterBuilders.termFilter(
            "tags", "spam")));

    SearchRequestBuilder searchReq = new SearchRequestBuilder(client)
        .setQuery(QueryBuilders.matchAllQuery())
        .setFilter(noSpamFilter)
        .setIndices("products")
        .setTypes("product");

    SearchResponse resp = searchReq.execute().actionGet();

```

I had indexed four products, three with tags, one without the field  
product 1 tags: "a", "b", "spam"  
product 2 tags: "d", "e", "e"  
product 3 tags: "a", "b", "spam"  
product 4 had no tags field

reply was product2 and product4 - do you have any special mappings or  
any other special configuration?

--Alexander

--

---

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [November 1, 2012, 2:07am UTC](https://discuss.elastic.co/t/term-filter-for-array-list-not-working/9028/3 "2012-11-01T02:07:38Z")

</div>

im still confused.. i see that is working for you..  
but in my case, i have no clue why its not working..

e.g., i have a document like this -  
curl -XGET '[http://localhost:9200/capture-widget/content/161\_89?pretty=true](http://localhost:9200/capture-widget/content/161_89?pretty=true)'  
{  
"\_index" : "capture-widget",  
"\_type" : "content",  
"\_id" : "161\_89",  
"\_version" : 3,  
"exists" : true, "\_source" :  
{"tags":[" **SPAM**"],"moderated\_and\_approved":true,"brand\_id":"161","actor\_id":"1","score":0.0}  
}

and my search query looks like this -  
curl -XGET '[http://localhost:9200/capture-widge/content/\_search?pretty=true](http://localhost:9200/capture-widge/content/_search?pretty=true)'  
-d '  
{"query":{"filtered":{"query":{"match\_all":{}},"filter":{"and":{"filters":[{"term":{"brand\_id":"161"}},  
{"not": {"terms":{"tags": [" **SPAM**"] }}} ]}}}}}}'

the results contain 161\_89..  
how is it possible?

thanks

On Sat, Sep 15, 2012 at 6:18 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hi
> 
> On Fri, Sep 14, 2012 at 11:33 PM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com)  
> wrote:
> 
> > can someone tell me what i am doing wrong?  
> > basically i have an index of documents that have a field called "tags".  
> > it is a list of strings.  
> > one of the documents has  
> > "tags" : ["spam"]
> > 
> > but this filter in java is not taking effect -
> > 
> > ```
> > FilterBuilder noSpamFilter = FilterBuilders.orFilter(
> > FilterBuilders.missingFilter("tags")
> > 
> > ```
> 
> ,FilterBuilders.notFilter(FilterBuilders.termFilter(
> 
> > ```
> > "tags", "spam")));
> > 
> > ```
> > 
> > when i do a search with this filter, the document with spam tag is still  
> > being returned. am i using it incorrectly?
> 
> Testing it with ES 0.19.8 works flawlessly for me. You are sure
> 
> This is my sample source
> 
> ```
> FilterBuilder noSpamFilter = FilterBuilders.orFilter(
> FilterBuilders.missingFilter("tags")
> ,FilterBuilders.notFilter(FilterBuilders.termFilter(
> "tags", "spam")));
> 
> SearchRequestBuilder searchReq = new SearchRequestBuilder(client)
> .setQuery(QueryBuilders.matchAllQuery())
> .setFilter(noSpamFilter)
> .setIndices("products")
> .setTypes("product");
> 
> SearchResponse resp = searchReq.execute().actionGet();
> 
> ```
> 
> I had indexed four products, three with tags, one without the field  
> product 1 tags: "a", "b", "spam"  
> product 2 tags: "d", "e", "e"  
> product 3 tags: "a", "b", "spam"  
> product 4 had no tags field
> 
> reply was product2 and product4 - do you have any special mappings or  
> any other special configuration?
> 
> --Alexander
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 1, 2012, 3:19am UTC](https://discuss.elastic.co/t/term-filter-for-array-list-not-working/9028/4 "2012-11-01T03:19:21Z")

</div>

How are tags mapped? If tags are analyzed (which is default), " **SPAM**"  
would be indexed as " **spam**" and as a result your filter "terms":{"tags":  
[" **SPAM**"] }} wouldn't match anything

On Wednesday, October 31, 2012 10:07:45 PM UTC-4, T Vinod Gupta wrote:

> im still confused.. i see that is working for you..  
> but in my case, i have no clue why its not working..
> 
> e.g., i have a document like this -  
> curl -XGET '  
> [http://localhost:9200/capture-widget/content/161\_89?pretty=true](http://localhost:9200/capture-widget/content/161_89?pretty=true)'  
> {  
> "\_index" : "capture-widget",  
> "\_type" : "content",  
> "\_id" : "161\_89",  
> "\_version" : 3,  
> "exists" : true, "\_source" :  
> {"tags":[" **SPAM**"],"moderated\_and\_approved":true,"brand\_id":"161","actor\_id":"1","score":0.0}  
> }
> 
> and my search query looks like this -  
> curl -XGET '  
> [http://localhost:9200/capture-widge/content/\_search?pretty=true](http://localhost:9200/capture-widge/content/_search?pretty=true)' -d '  
> {"query":{"filtered":{"query":{"match\_all":{}},"filter":{"and":{"filters":[{"term":{"brand\_id":"161"}},  
> {"not": {"terms":{"tags": [" **SPAM**"] }}} ]}}}}}}'
> 
> the results contain 161\_89..  
> how is it possible?
> 
> thanks
> 
> On Sat, Sep 15, 2012 at 6:18 AM, Alexander Reelsen \<[a...@spinscale.de](mailto:a...@spinscale.de)\<javascript:\>
> 
> > wrote:
> 
> > Hi
> > 
> > On Fri, Sep 14, 2012 at 11:33 PM, T Vinod Gupta \<[tvi...@readypulse.com](mailto:tvi...@readypulse.com)\<javascript:\>\>  
> > wrote:
> > 
> > > can someone tell me what i am doing wrong?  
> > > basically i have an index of documents that have a field called "tags".  
> > > it is a list of strings.  
> > > one of the documents has  
> > > "tags" : ["spam"]
> > > 
> > > but this filter in java is not taking effect -
> > > 
> > > ```
> > > FilterBuilder noSpamFilter = FilterBuilders.orFilter(
> > > FilterBuilders.missingFilter("tags")
> > > 
> > > ```
> > 
> > ,FilterBuilders.notFilter(FilterBuilders.termFilter(
> > 
> > > ```
> > > "tags", "spam")));
> > > 
> > > ```
> > > 
> > > when i do a search with this filter, the document with spam tag is  
> > > still being returned. am i using it incorrectly?
> > 
> > Testing it with ES 0.19.8 works flawlessly for me. You are sure
> > 
> > This is my sample source
> > 
> > ```
> > FilterBuilder noSpamFilter = FilterBuilders.orFilter(
> > FilterBuilders.missingFilter("tags")
> > ,FilterBuilders.notFilter(FilterBuilders.termFilter(
> > "tags", "spam")));
> > 
> > SearchRequestBuilder searchReq = new SearchRequestBuilder(client)
> > .setQuery(QueryBuilders.matchAllQuery())
> > .setFilter(noSpamFilter)
> > .setIndices("products")
> > .setTypes("product");
> > 
> > SearchResponse resp = searchReq.execute().actionGet();
> > 
> > ```
> > 
> > I had indexed four products, three with tags, one without the field  
> > product 1 tags: "a", "b", "spam"  
> > product 2 tags: "d", "e", "e"  
> > product 3 tags: "a", "b", "spam"  
> > product 4 had no tags field
> > 
> > reply was product2 and product4 - do you have any special mappings or  
> > any other special configuration?
> > 
> > --Alexander
> > 
> > --

--

---

<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, 3:06am UTC](https://discuss.elastic.co/t/term-filter-for-array-list-not-working/9028/5 "2017-07-06T03:06:38Z")

</div>


