elasticsearch 在弹性搜索中过滤出分支
我想在elastic search 2.4中过滤一些数据。 更具体地说,我只想考虑“island”标签下的记录。
elasticsearch 在弹性搜索中过滤出分支,
elasticsearch,dsl,
elasticsearch,Dsl,我想在elastic search 2.4中过滤一些数据。 更具体地说,我只想考虑“island”标签下的记录。 如果我这样过滤: filter : [{term: {Artists.Artist.Records.label : "Island"}}] 我会失去英里数,但保留另外两个,因为他们有一个岛屿标签。这很好,但我希望丢失所有none island记录,但仍然保留顶部的所有数据 因此: { "Artists": [ { "Artist": "Tom Waits"
如果我这样过滤:
filter : [{term: {Artists.Artist.Records.label : "Island"}}]
我会失去英里数,但保留另外两个,因为他们有一个岛屿标签。这很好,但我希望丢失所有none island记录,但仍然保留顶部的所有数据
因此:
{
"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"
}
]
}
]
}
可能吗?谢谢 我相信这可以通过内部点击功能来实现。您的查询如下所示:
{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"nested": {
"path": "Artists.Artist.Records",
"filter": {
"term": {
"Records.label": "Island"
}
},
"inner_hits" : {}
}
}
}
}
}