【发布时间】:2013-10-18 16:46:15
【问题描述】:
我目前在弹性搜索(文档)和与这些文档相关的孩子(cmets)中索引了父母。 我的第一个目标是根据子查询搜索包含 N 个以上 cmets 的文档。这是我的做法:
documents/document/_search
{
"min_score": 0,
"query": {
"has_child" : {
"type" : "comment",
"score_type" : "sum",
"boost": 1,
"query" : {
"range": {
"date": {
"lte": 20130204,
"gte": 20130201,
"boost": 1
}
}
}
}
}
}
我使用 score 来计算文档的 cmets 数量,然后使用“min_score”按此数量过滤文档。 现在,我的目标不仅是搜索 cmets,还搜索与该文档相关的其他几个子文档,始终基于频率。类似于下面的查询:
documents/document/_search
{
"query": {
"match_all": {
}
},
"filter" : {
"and" : [{
"query": {
"has_child" : {
"type" : "comment",
"query" : {
"range": {
"date": {
"lte": 20130204,
"gte": 20130201
}
}
}
}
}
},
{
"or" : [
{"query": {
"has_child" : {
"type" : "comment",
"query" : {
"match": {
"text": "Finally"
}
}
}
}
},
{ "query": {
"has_child" : {
"type" : "comment",
"query" : {
"match": {
"text": "several"
}
}
}
}
}
]
}
]
}
}
上面的查询工作正常,但它不像第一个那样根据频率进行过滤。由于过滤器是在计算分数之前计算的,因此我不能使用 min_score 过滤每个子查询。
有解决这个问题的办法吗?
【问题讨论】:
标签: elasticsearch aggregate-functions frequency-analysis elasticsearch-plugin