Term Filter not working

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.

{
"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.

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?

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
}
}
}

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

"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

Hi,

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

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

Does this return any results?

No, still no results with that query either.

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.

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?

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

curl -XGET 'http://localhost:9200/{INDEX}/_mapping/{TYPE}/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

{
"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?