LoginSignup
0
0

More than 5 years have passed since last update.

Elasticsearchのstring fieldに対する各filterの挙動

Posted at

個人的メモ

準備

$ curl -XPUT localhost:9200/test_idx/test_type/1 -d '{"test_str": "foo"}'
{"_index":"test_idx","_type":"test_type","_id":"1","_version":1,"created":true}
$ curl -XPUT localhost:9200/test_idx/test_type/2 -d '{"test_str": ""}'
{"_index":"test_idx","_type":"test_type","_id":"2","_version":1,"created":true}
$ curl -XPUT localhost:9200/test_idx/test_type/3 -d '{"test_str": null}'
{"_index":"test_idx","_type":"test_type","_id":"3","_version":1,"created":true}

filtering

exitis filter

GET test_idx/test_type/_search
{
  "filter": {
    "exists": {
      "field": "test_str"
    }
  }
}
{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 1,
      "hits": [
         {
            "_index": "test_idx",
            "_type": "test_type",
            "_id": "1",
            "_score": 1,
            "_source": {
               "test_str": "foo"
            }
         },
         {
            "_index": "test_idx",
            "_type": "test_type",
            "_id": "2",
            "_score": 1,
            "_source": {
               "test_str": ""
            }
         }
      ]
   }
}

missing filter

GET test_idx/test_type/_search
{
  "filter": {
    "missing": {
      "field": "test_str"
    }
  }
}
{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "test_idx",
            "_type": "test_type",
            "_id": "3",
            "_score": 1,
            "_source": {
               "test_str": null
            }
         }
      ]
   }
}

term filter (by empty string)

GET test_idx/test_type/_search
{
  "filter": {
    "term": {
      "test_str": ""
    }
  }
}
{
   "took": 5,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
   }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0