3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elasticsearchでフィールド有無検索

Posted at

Elasticsearchでは必要の無いフィールドは存在させないでデータ登録できます。

そんなフィールドの有無を検索したいときの検索例です。

指定したフィールドのあるデータの検索

index_nameからfield_nameフィールドが存在するデータの検索をする例

GET index_name/_search
{
  "query": {
    "exists": {
      "field": "field_name"
    }
  }
}

指定したフィールドの無いデータの検索

index_nameからfield_nameフィールが存在しないデータの検索をする例

GET index_name/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "field_name"
          }
        }
      ]
    }
  }
}

いずれかのフィールドのないデータの検索

index_nameからfield_1かfield_2のいずれかのフィールが存在しないデータの検索をする例

GET index_name/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must_not": [
              {
                "exists": {
                  "field": "field_1"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must_not": [
              {
                "exists": {
                  "field": "field_2"
                }
              }
            ]
          }
        }
      ]
    }
  }
}
3
7
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
3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?