【发布时间】:2019-09-27 18:34:38
【问题描述】:
我的索引中有一些文档:
POST "/index/thing/_bulk" -s -d'
{ "index":{ "_id": 1 } }
{ "title":"One thing"}
{ "index":{ "_id": 2 } }
{ "title":"Second thing"}
{ "index":{ "_id": 3 } }
{ "title":"Three things"}
{ "index":{ "_id": 4 } }
{ "title":"And so fourth"}
{ "index":{ "_id": 5 } }
{ "title":"Five things"}
'
我还有包含用户collection 的文档,这些用户通过文档id 属性链接到其他文档(事物),如下所示:
PUT /index/collection/1
{
"items": [
{"id": 1, "time_added": "2017-08-07T09:07:15.000Z", "condition": "fair"},
{"id": 3, "time_added": "2019-08-07T09:07:15.000Z", "condition": "good"},
{"id": 4, "time_added": "2016-08-07T09:07:15.000Z", "condition": "poor"}
]
}
然后我使用terms lookup 来获取用户集合中的所有内容,如下所示:
GET /documents/_search
{
"query" : {
"terms" : {
"_id" : {
"index" : "index",
"type" : "collection",
"id" : 1,
"path" : "items.id"
}
}
}
}
这很好用。我得到了集合中的三个文档,并且可以根据需要搜索、排序和使用聚合。
但是有没有办法根据collection 文档中的属性(在本例中为time_added 或condition)来聚合、过滤和排序这些文档?假设我想根据time_added 进行排序或从集合中过滤condition=="good"?
也许可以将脚本应用于collection 以对其中的项目进行排序或过滤?感觉这和left-join之类的sql已经很接近了,所以也许Elastic Search是错误的工具?
【问题讨论】:
标签: elasticsearch