Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: Searching on boolean field

I have a couple of documents in an Elasticsearch Cluster having a field isInFight holding a boolean value. Mapping is set correctly (already double-checked this) to boolean.

When I run a search with:

 curl -XGET localhost:9200/default/_search --data '{"query": {"term": {"isInFight": true}}}'

I get documents returned with the field being true and false. Changing the value in my search query to false no documents are returned at all.

To me this looks like the term query checked for the field being present or not rather then for it's value. Everything I found on the internet suggests that this query is the way to go though.

Am I missing something here? Is there a known bug regarding this?

The Elasticsearch in question is version 5.5.2 with lucene version 6.6.0 on an ubuntu 16.04 server.

like image 747
Dero Avatar asked Aug 13 '18 15:08

Dero


1 Answers

Try this in my local elasticsearch and didn't find the issue

POST test_index/doc
{
  "id": 1,
  "isInFight": false
}

POST test_index/doc
{
  "id": 2,
  "isInFight": true
}

POST test_index/doc
{
  "id": 3,
  "isInFight": true
}

GET test_index/doc/_search
{
  "query": {
    "term": { "isInFight": false }
  }
}

and got this result

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "test_index",
        "_type": "doc",
        "_id": "AWU2Dxm7GR2l1TPuyKhN",
        "_score": 0.2876821,
        "_source": {
          "id": 1,
          "isInFight": false
        }
      }
    ]
  }
}
like image 169
deerawan Avatar answered Nov 15 '22 10:11

deerawan