2016-07-13 14 views
0

ESスキームでは、複数のネストされたコースドキュメントを含む学生ドキュメントをモデル化します。さらに(私は数学と経済学をとっているすべての学生を照会するAND条件付きの弾性検索ネストされたドキュメント

{ 
    "_index": "index_classroom", 
    "_type": "content", 
    "_id": "6170_130", 
    "_score": 0.72833073, 
    "_source": { 
     "courses": [ 
     { 
      "name": "maths", 
      "grade": "A" 
     }, 
     { 
      "name": "economics", 
      "grade": "A+" 
     } 
     ] 
    } 
    } 

{ 
    "index_classroom": { 
    "mappings": { 
     "content": { 
     "dynamic": "false", 
     "properties": { 
      "courses": { 
      "type": "nested", 
      "properties": { 
       "grade": { 
       "type": "integer" 
       }, 
       "name": { 
       "type": "string", 
       "analyzer": "analyzer_keyword" 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
    } 

サンプルドキュメント:私はコースのXとY

マッピングを持っている学生を検索したいです追加するのは「生物学ではない」です。

ありがとう!

+0

私は弾性2.3.3を使用しています – lazywiz

答えて

2

これはあなたのクエリです:

{ 
    "query": { 
     "bool": { 
      "must": [ 
       { 
        "nested": { 
         "path": "courses", 
         "query": { 
          "match": { 
           "courses.name": "economics" 
          } 
         } 
        } 
       }, 
       { 
        "nested": { 
         "path": "courses", 
         "query": { 
          "match": { 
           "courses.name": "maths" 
          } 
         } 
        } 
       } 
      ], 
      "must_not": [ 
       { 
        "nested": { 
         "path": "courses", 
         "query": { 
          "match": { 
           "courses.name": "Biology" 
          } 
         } 
        } 
       } 
      ] 
     } 
    } 
} 
関連する問題