2016-12-21 7 views
1

私のマッピングを動作していないネストされたオブジェクトのためのフィルタが存在するがある:Elasticsearch 2.4、

"properties": { 
    "user": { 
    "type": "nested", 
    "properties": { 
     "id": { 
     "type": "integer" 
     }, 
     "is_active": { 
     "type": "boolean", 
     "null_value": false 
     }, 
     "username": { 
     "type": "string" 
     } 
    } 
    }, 

私はuserフィールドを持っていないすべての文書を取得したいです。

私が試した:すべての文書を返します

GET /index/type/_search 
{ 
    "query": { 
    "bool": { 
     "must_not": [ 
     { 
      "exists": { 
      "field": "user" 
      } 
     } 
     ] 
    } 
    } 
} 

を。 ElasticSearch 2.x exists filter for nested field doesn't workに基づいて、私も試してみました:

GET /index/type/_search 
{ 
    "query": { 
    "nested": { 
     "path": "user", 
     "query": { 
     "bool": { 
      "must_not": [ 
      { 
       "exists": { 
       "field": "user" 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

0の文書を返します。

userフィールドがないすべてのドキュメントを取得する正しいクエリは何ですか?

+0

あなたは 'の存在をテストしようとすることができます代わりにuser.id'フィールド?親ドキュメントに 'user'フィールドがない場合、' user.id'フィールドもありません。 – Val

+0

私は十分にうまくいくだろうと思うが、ユーザーが設定されているが空であるという最悪のケースは見逃してしまう。 – pmishev

答えて

2

ここでは、利用者の親を使用してみてください、それがされている必要があります:

GET /index/type/_search 
{ 
    "query": { 
    "bool": { 
     "must_not": [ 
     { 
      "nested": { 
      "path": "user", 
      "query": { 
       "exists": { 
       "field": "user" 
       } 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
0

、私は正しい構文を見つけOBJ

GET users/users/_search 
{ 
    "query": { 
    "bool": { 
     "must_not": [ 
     { 
      "exists": { 
      "field": "obj.user" 
      } 
     } 
     ] 
    } 
    } 
} 
+0

ユーザーには親がありません。ドキュメント内のフィールドであり、ネストされたオブジェクトではありません – pmishev

関連する問題