2017-10-26 3 views
0

ネストされたオブジェクトを持つインデックスがあります。マッピングは次のようなものです:Elasticsearch 5.xネストされたオブジェクトが存在しないドキュメントを見つける

{ 
    "mappings": { 
    "my_type": { 
     "properties": { 
     "group": {"type": "string"}, 
     "users": { 
      "type": "nested", 
      "properties": { 
       "first": {"type": "string"}, 
       "last": {"type": "string"} 
      } 
     } 
     } 
    } 
    } 
} 

「ユーザー」がないすべてのドキュメントを見つける必要があります。

GET /my_index/my_type/_search 
{ 
    "query": { 
     "nested": { 
      "path": "users", 
      "query": { 
       "bool": { 
        "must": [ 
        { 
         "exists": { 
          "field": "users" 
          } 
         } 
        ] 
       } 
      } 
     } 
    } 
} 

が、私は逆を行う方法がわからない - 私はユーザーが持っている唯一の文書を見つける方法を見ることができます。すべてのポインタ?

答えて

1

must_notをネストされたブールクエリと組み合わせて外部ブールクエリとして使用できます。 5.3.0

に検証

{ 
"query": { 
    "bool": { 
    "must_not": [ 
     { 
     "nested": { 
      "path": "users", 
      "query": { 
      "bool": { 
       "filter": { 
       "exists": { 
        "field": "users" 
       } 
       } 
      } 
      } 
     } 
     } 
    ] 
    } 
} 

}

関連する問題