お世話になっております
"mappings" : {
"default" : {
"properties" : {
"create_date" : {
"type" : "date",
"format" : "yyyy-MM-dd HH:mm:ss"
},
....
↑の定義でmappingされたフィールドに、下記のようにnullが設定された場合、
"create_date" : null
この値が設定されているドキュメントを引っ張ってくるクエリ条件はどのように書けばいいのでしょうか?
お世話になっております
"mappings" : {
"default" : {
"properties" : {
"create_date" : {
"type" : "date",
"format" : "yyyy-MM-dd HH:mm:ss"
},
....
↑の定義でmappingされたフィールドに、下記のようにnullが設定された場合、
"create_date" : null
この値が設定されているドキュメントを引っ張ってくるクエリ条件はどのように書けばいいのでしょうか?
こちらでは、nullでない値が入ったフィールドの検索でexistsクエリが紹介されていますが、
下の方に、missing queryの説明があり、こう書いてあります。
This query returns documents that have no value in the user field.
手元のテストデータではこれでNullのフィールドをひっかけることができました。
以下、こちらで試した内容です。
(mapping設定は、create_dateについては提示されたものそのまま)
POST forum0714/articles/2
{
  "articles_id": 2,
  "subject": "Hello World",
  "body": "Hello World。 hoge",
  "create_date": null
}
   "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field": "create_date"
                }
            }
        }
    }
おしゃる通りに試したところ上手く取得できました。
大変助かりました。ありがとうございました!
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
© 2020. All Rights Reserved - Elasticsearch
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.