2017-03-01 7 views
0

弾性検索2.4でいくつかのデータをフィルタリングしたいと思います。 具体的には、「島」ラベルの下にあるレコードのみを検討したいと考えています。
私はこのようなフィルタする場合:弾性検索のブランチをフィルタリングする

filter : [{term: {Artists.Artist.Records.label : "Island"}}] 

を私はマイルを失うことになるが、彼らは島のラベルを持っているので、2人を保ちます。それは良いですが、私はすべての島のレコードをを失っても、上からすべてのデータを保持したいと思います。

だから、与えられた:

{ 
    "Artists": [ 
    { 
     "Artist": "Tom Waits", 
     "Records": [ 
     { 
      "id": 1, 
      "title": "Rain dogs", 
      "label": "Island" 
     }, 
     { 
      "id": 2, 
      "title": "SwordFishTrombones", 
      "label": "Island" 
     }, 
     { 
      "id": 3, 
      "title": "Bone Machine", 
      "label": "ANTI" 
     } 
     ] 
    }, 
    { 
     "Artist": "dEUS", 
     "Records": [ 
     { 
      "id": 112, 
      "title": "Worst Case Scenario", 
      "label": "Island" 
     }, 
     { 
      "id": 2213, 
      "title": "Keep you close", 
      "label": "Universal" 
     } 
     ] 
    }, 
    { 
     "Artist": "Miles", 
     "Records": [ 
     { 
      "id": 42, 
      "title": "Kind of blue", 
      "label": "columbia" 
     } 
     ] 
    } 
    ] 
} 

私はで終わるしたいと思います:

{ 
    "Artists": [ 
    { 
     "Artist": "Tom Waits", 
     "Records": [ 
     { 
      "id": 1, 
      "title": "Rain dogs", 
      "label": "Island" 
     }, 
     { 
      "id": 2, 
      "title": "SwordFishTrombones", 
      "label": "Island" 
     } 
     ] 
    }, 
    { 
     "Artist": "dEUS", 
     "Records": [ 
     { 
      "id": 112, 
      "title": "Worst Case Scenario", 
      "label": "Island" 
     } 
     ] 
    } 
    ] 
} 

が可能ということですか?ありがとう!

答えて

1

これはインナーヒット機能で実現できると思います。クエリは次のようになります。

{ 
    "query": { 
    "filtered": { 
     "query": {"match_all": {}}, 
     "filter": { 
     "nested": { 
      "path": "Artists.Artist.Records", 
      "filter": { 
      "term": { 
       "Records.label": "Island" 
      } 
      }, 
      "inner_hits" : {} 
     } 
     } 
    } 
    } 
}