# Term Filter not working

**URL:** https://discuss.elastic.co/t/term-filter-not-working/37159
**Category:** Elasticsearch
**Created:** [December 14, 2015, 7:36pm UTC](https://discuss.elastic.co/t/term-filter-not-working/37159 "2015-12-14T19:36:33Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![NathanCoats](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathancoats/32/6619_2.png) [@NathanCoats](https://discuss.elastic.co/u/NathanCoats)
#### Post date: [December 14, 2015, 7:36pm UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/1 "2015-12-14T19:36:33Z")

</div>

Hey everybody i have been trying to get my query working for a while now, and i finally broke down and added a new field into my mongo database. i use mongo-connector to import the data from mongo to elastic search.

> **[mongodb-labs/mongo-connector](https://github.com/mongodb-labs/mongo-connector/wiki/Usage%20with%20ElasticSearch)**
>
> mongo-connector - Data replication from MongoDB to MongoDB, Elasticsearch, Solr, and more!

{  
"query":{  
"function\_score":{  
"query":{  
"bool":{  
"must":[  
{  
"filtered":{  
"filter":{  
"type":{  
"value":"products"  
}  
}  
}  
},  
{  
"query\_string":{  
"query":"wood",  
"fields":[  
"mpn",  
"upc",  
"brand",  
"title",  
"keywords",  
"description"  
]  
}  
},  
{  
"term":{  
"channels.AdamsProduct":true  
}  
},  
{  
"term":{  
"search":true  
}  
}  
]  
}  
},  
"functions":[  
]  
}  
}  
}

here is my query. if i take out { "term" : {"search" : true}} it works fine, but if i leave it in there it acts as if the field "search" is always false, so it returns no hits. i know there are many results that have search = true.  
if i change term to match it still returns nothing.

I have done a little research about the problem and from what i can understand it is because the field is not indexed, it makes it so it is not a searchable term. this is a production server, that i need to fix quickly, so i don't want to use the trial and error method to fix it. if anybody has an idea about what is wrong please help me out, this all kind of got dropped in my lap after 2 of my bosses quit, making me the one in charge of this stuff.

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [December 14, 2015, 8:17pm UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/2 "2015-12-14T20:17:04Z")

</div>

Hi,

My suggestion is start with the bool query and just have { "term" : {"search" : true}}. Does this work as the only condition? Then add back each query one by one and see where you start getting no results. Also are you search search is a boolean? And not a type string for example?

---

<div class="post-metadata">

### Author: ![NathanCoats](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathancoats/32/6619_2.png) [@NathanCoats](https://discuss.elastic.co/u/NathanCoats)
#### Post date: [December 14, 2015, 8:34pm UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/3 "2015-12-14T20:34:23Z")

</div>

Thank you for your suggestions,  
i have made sure that it is a boolean, and ran the query and still no luck  
{  
"query": {  
"term": {  
"search": true  
}  
}  
}

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [December 14, 2015, 11:20pm UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/4 "2015-12-14T23:20:47Z")

</div>

Maybe if you post your indexname/\_mapping we can see what is happening.

---

<div class="post-metadata">

### Author: ![NathanCoats](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathancoats/32/6619_2.png) [@NathanCoats](https://discuss.elastic.co/u/NathanCoats)
#### Post date: [December 15, 2015, 12:16am UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/5 "2015-12-15T00:16:17Z")

</div>

"products": {  
"properties": {  
"amazon": {  
"properties": {}  
},  
"brand": {  
"type": "string"  
},  
"buyLine": {  
"type": "string"  
},  
"categories": {  
"type": "string"  
},  
"channels": {  
"properties": {}  
},  
"deadstock": {  
"type": "string"  
},  
"description": {  
"type": "string"  
},  
"dimensions": {  
"properties": {  
"height": {  
"type": "long"  
},  
"length": {  
"type": "long"  
},  
"weight": {  
"type": "long"  
},  
"width": {  
"type": "long"  
}  
}  
},  
"facets": {  
"properties": {  
"attributeId": {  
"type": "long"  
},  
"valueId": {  
"type": "long"  
}  
}  
},  
"features": {  
"type": "string"  
},  
"hasImages": {  
"type": "boolean"  
},  
"images": {  
"properties": {  
"id": {  
"type": "string"  
},  
"md5": {  
"type": "string"  
},  
"name": {  
"type": "string"  
},  
"sort": {  
"type": "long"  
}  
}  
},  
"inventory": {  
"properties": {  
"availability": {  
"properties": {  
"phac": {  
"properties": {  
"cost": {  
"type": "double"  
},  
"price": {  
"type": "double"  
},  
"qty": {  
"type": "long"  
}  
}  
},  
"plumbersstock": {  
"properties": {  
"cost": {  
"type": "double"  
},  
"price": {  
"type": "double"  
},  
"qty": {  
"type": "long"  
}  
}  
},  
"stockmarket": {  
"properties": {  
"cost": {  
"type": "double"  
},  
"price": {  
"type": "double"  
},  
"qty": {  
"type": "long"  
}  
}  
},  
"swplumbing": {  
"properties": {  
"cost": {  
"type": "double"  
},  
"price": {  
"type": "double"  
},  
"qty": {  
"type": "long"  
}  
}  
},  
"tdp": {  
"properties": {  
"cost": {  
"type": "double"  
},  
"price": {  
"type": "double"  
},  
"qty": {  
"type": "long"  
}  
}  
},  
"yow": {  
"properties": {  
"cost": {  
"type": "double"  
},  
"price": {  
"type": "double"  
},  
"qty": {  
"type": "long"  
}  
}  
}  
}  
},  
"locations": {  
"properties": {  
"branch": {  
"type": "string"  
},  
"location": {  
"type": "string"  
}  
}  
}  
}  
},  
"keywords": {  
"type": "string"  
},  
"meta": {  
"properties": {  
"description": {  
"type": "string"  
},  
"keywords": {  
"type": "string"  
},  
"robots": {  
"type": "string"  
},  
"slug": {  
"type": "string"  
},  
"title": {  
"type": "string"  
}  
}  
},  
"mpn": {  
"type": "string"  
},  
"origin": {  
"type": "string"  
},  
"part": {  
"type": "boolean"  
},  
"priceLine": {  
"type": "string"  
},  
"pricing": {  
"properties": {  
"cost": {  
"type": "double"  
},  
"gpOverride": {  
"type": "string"  
},  
"listPrice": {  
"type": "double"  
},  
"mapMethod": {  
"type": "string"  
},  
"mapPrice": {  
"type": "double"  
},  
"minsSaleQty": {  
"type": "long"  
},  
"price": {  
"type": "double"  
}  
}  
},  
"productId": {  
"type": "long"  
},  
"products": {  
"properties": {  
"parts": {  
"type": "string"  
},  
"recommended": {  
"type": "string"  
},  
"related": {  
"type": "string"  
},  
"required": {  
"type": "string"  
}  
}  
},  
"resources": {  
"properties": {  
"id": {  
"type": "string"  
},  
"name": {  
"type": "string"  
},  
"sort": {  
"type": "long"  
}  
}  
},  
"search": {  
"type": "boolean"  
},  
"shipping": {  
"properties": {  
"dropShipped": {  
"type": "boolean"  
},  
"flatRate": {  
"type": "boolean"  
},  
"flatRatePrice": {  
"type": "long"  
},  
"foam": {  
"type": "boolean"  
},  
"free": {  
"type": "boolean"  
},  
"freight": {  
"type": "boolean"  
},  
"insurance": {  
"type": "boolean"  
},  
"leadTime": {  
"type": "long"  
}  
}  
},  
"status": {  
"type": "long"  
},  
"title": {  
"type": "string"  
},  
"uom": {  
"type": "string"  
},  
"uomQty": {  
"type": "long"  
},  
"upc": {  
"type": "string"  
},  
"videos": {  
"properties": {  
"id": {  
"type": "string"  
},  
"name": {  
"type": "string"  
},  
"sort": {  
"type": "long"  
}  
}  
}  
}  
},

it is quite large but here is the index/\_mapping for the database i am using

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [December 15, 2015, 12:44am UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/6 "2015-12-15T00:44:13Z")

</div>

Hi,

I don't really see anything obvious. It seems like you should be able to do:

```auto
{
  "query": {
    "term": {
      "search": {
        "value": true
      }
    }
  }
}

```

Does this return any results?

---

<div class="post-metadata">

### Author: ![NathanCoats](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathancoats/32/6619_2.png) [@NathanCoats](https://discuss.elastic.co/u/NathanCoats)
#### Post date: [December 15, 2015, 12:58am UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/7 "2015-12-15T00:58:13Z")

</div>

No, still no results with that query either.

---

<div class="post-metadata">

### Author: ![NathanCoats](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathancoats/32/6619_2.png) [@NathanCoats](https://discuss.elastic.co/u/NathanCoats)
#### Post date: [December 15, 2015, 1:13am UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/8 "2015-12-15T01:13:10Z")

</div>

What is interesting is if i do  
{  
"query": {  
"term": {  
"search": {  
"value": false  
}  
}  
}  
}

i get no results either, it is like the field isn't registered at all

but if i go into  
\_plugin/head/  
to the browser section  
i can manually choose the options from the drop-downs, making the same delimiters apply, and i actually get results.

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [December 15, 2015, 1:20am UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/9 "2015-12-15T01:20:49Z")

</div>

From the head plugin there is the structured query, where you can show the query source & raw json. So you may want to give that a try. The only thing I can think of is if you're searching the wrong type?

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [December 15, 2015, 1:23am UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/10 "2015-12-15T01:23:26Z")

</div>

Is the mapping you posted from your definition or from the mapping API. The  
use of the latter is important. You can also get the mapping for an  
individual field:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html)

curl -XGET '[http://localhost:9200/{INDEX}/\_mapping/{TYPE}/field/text](http://localhost:9200/%7BINDEX%7D/_mapping/%7BTYPE%7D/field/text)'

Two things to look for. The first is that the field is indexed and the  
second is that it is a boolean and not a string.

Ivan

---

<div class="post-metadata">

### Author: ![NathanCoats](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathancoats/32/6619_2.png) [@NathanCoats](https://discuss.elastic.co/u/NathanCoats)
#### Post date: [December 15, 2015, 3:23am UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/11 "2015-12-15T03:23:42Z")

</div>

{  
"typhoeus": {  
"mappings": {  
"products": {  
"search": {  
"full\_name": "search",  
"mapping": { "search": { "type": "boolean"}}  
}  
}  
}  
}  
}

when i run the curl request i get the following results, it is a boolean, but it does not appear to be indexed, how do i index the field?

---

<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 5, 2017, 11:31pm UTC](https://discuss.elastic.co/t/term-filter-not-working/37159/12 "2017-07-05T23:31:05Z")

</div>


