# Can't seem to get results for boolean fields

**URL:** <https://discuss.elastic.co/t/cant-seem-to-get-results-for-boolean-fields/38265>\
**Category:** Elasticsearch\
**Created:** [January 3, 2016, 8:39am UTC](https://discuss.elastic.co/t/cant-seem-to-get-results-for-boolean-fields/38265 "2016-01-03T08:39:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trezy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trezy/32/6931_2.png) [@trezy](https://discuss.elastic.co/u/trezy)\
**Post date:** [January 3, 2016, 8:39am UTC](https://discuss.elastic.co/t/cant-seem-to-get-results-for-boolean-fields/38265/1 "2016-01-03T08:39:09Z")

</div>

Hey guys, I'm having issues trying to search against boolean fields and I can't seem to figure out what the deal is. I've been googling and banging my head against the problem for days now. I've got a Node application and I'm using Mongoosastic to make create indexes from my MongoDB. It's also creating mappings based on my Mongoose models.

Here's the whole project: [https://github.com/FuelRats/api.fuelrats.com](https://github.com/FuelRats/api.fuelrats.com)

Here's the particular model I'm working on: [https://github.com/FuelRats/api.fuelrats.com/blob/elasticsearch/api/models/rat.js](https://github.com/FuelRats/api.fuelrats.com/blob/elasticsearch/api/models/rat.js)

I've got the `archive` field indexed as a boolean and regardless of how I run the search I can't seem to get any results. Here's what my query looks like at the moment:

```
{
  query: {
    filtered: {
      query: {
        must: [
          match: {
            CMDRname: {
              term: 'Trezy',
              fuzziness: 'auto'
            }
          }
        ]
      },
      filter: {
        term: {
          archive: true
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [January 4, 2016, 7:43pm UTC](https://discuss.elastic.co/t/cant-seem-to-get-results-for-boolean-fields/38265/2 "2016-01-04T19:43:34Z")

</div>

Hi,

I am not sure where the exact problem is, maybe it is related to the mapping that is created for you. You can check the mapping with:

`GET /fuelrats/_mapping`

(where "fuelrats" is the index name)

Here is a pure Elasticsearch example that you can paste directly into [Sense](https://www.elastic.co/guide/en/sense/current/index.html) and play around there:

We first create the index. I have not included all properties that you use though:

```auto
PUT /fuelrats
{
   "mappings": {
      "rat": {
         "properties": {
            "archive": {
               "type": "boolean"
            },
            "CMDRname": {
                type: "string"
            }
         }
      }
   }
}

```

Then we index a few documents:

```auto
POST /_bulk
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Crazy","archive":false}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Trezy","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Tracy","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Tracey","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Trezi","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Trazy","archive":true}

```

And fuzzy-search for them:

```auto
GET /_search
{
  "query": {
    "filtered": {
      "query": {
          "fuzzy": {
            "CMDRname": {
              "term": "Trezy",
              "fuzziness": "auto"
            }
          }
      },
      "filter": {
        "term": {
          "archive": true
        }
      }
    }
  }
}

```

This returns one hit; the document with CMDRname "Trezy". Note that fuzzy queries do not run through the analyzer. This is how Elasticsearch sees the "CMDRname" property of a "rat" document:

```auto
GET /fuelrats/_analyze
{
    "field": "CMDRname",
    "text": "Trezi"
}

```

this produces:

```auto
{
   "tokens": [
      {
         "token": "trezi",
         "start_offset": 0,
         "end_offset": 5,
         "type": "<ALPHANUM>",
         "position": 0
      }
   ]
}

```

So, the standard analyzer that is used for analyzing the text produces "trezi". But a fuzzy query will not run through this analysis stage and will internally try to fuzzy-match "Trezi" against "trezi". As the field "CMDRname" seems to be some kind of username you probably want to set index to "not\_analyzed" anyway (see [docs on index mapping options](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index.html)).

By the way, the filtered query is deprecated starting from Elasticsearch 2.0 (see also [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)). You should use a bool query instead:

```auto
GET /_search
{
  "query": {
    "bool": {
      "must": {
          "fuzzy": {
            "CMDRname": {
              "term": "Trezy",
              "fuzziness": "auto"
            }
          }
      },
      "filter": {
        "term": {
          "archive": true
        }
      }
    }
  }
}

```

I hope that solves your problem.

Daniel

---

<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:27pm UTC](https://discuss.elastic.co/t/cant-seem-to-get-results-for-boolean-fields/38265/3 "2017-07-05T23:27:15Z")

</div>


