2017-01-27 12 views
0

同じ構造のサブ文書の配列を持ち、同じサブ文書内の2つの条件をチェックする必要がある、弾性検索クエリを作成しようとしています。弾性検索同じサブ文書内の2つのフィールドを照らす

は私のデータは次のようになります。

{ 
    "_id": "5672ba7c0d71c93d159c408e", 
    "productId": "1723913526", 
    "title": "Digitab Tablet", 
    "instock": true, 
    "specifications": [{ 
     "category": "In the box", 
      "name": "Test1", 
      "value": "No" 
     }, { 
      "category": "Warranty", 
      "name": "Test2", 
      "value": "Yes" 
     }, { 
      "category": "General", 
      "name": "Test3", 
      "value": "Abcd" 
     }], 
    } 
} 

私は何をしようとしていることである:私は

をspecifications.nameが「Test1を」であり、同じサブ文書のspecifications.valueが「はい」である製品を取得する必要があります - それはプロを返すべきではありません

{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "wildcard": { 
      "specifications.name": "Test1*" 
      } 
     }, 
     { 
      "term": { 
      "instock": "true" 
      } 
     }, 
     { 
      "term": { 
      "specifications.value": "yes" 
      } 
     } 
     ], 
     "must_not": [], 
     "should": [] 
    } 
    } 
} 

問題はである:ここでは

は、私はこのために書かれているクエリです「値」はID「1723913526」です:「値」は:「はい」は「名前」:「テスト2」であり、「名前」ではなく「テスト1」です。

質問が明確になることを願っています。詳しい情報が必要な場合は、ご意見ください。

ありがとうございます。

答えて

1

specificationsnestedタイプであることを示すようにマッピングを変更する必要があります。

"mappings": { 
    "product": { 
    "properties": { 
     ... 
     "specifications": { 
     "type": "nested" 
     } 
    } 
    } 
} 

そしてなどの照会::のような

マッピング

"bool": { 
    "must": [{ 
    "nested": { 
     "path": "specifications", 
     "query": { 
     "bool": { 
      "must": [ 
      { "wildcard": { "specifications.first": "Test1*" }}, 
      { "term": { "specifications.value": "yes" }} 
      ] 
     } 
     } 
    }, 
    { 
     "term": { "instock": "true" } 
    } 
    }] 
} 
+0

おかげで、私はそれを試してみると、あなたを更新します。 –

関連する問題