【发布时间】:2015-03-23 17:06:00
【问题描述】:
我刚刚碰到“更像这样”的功能/api。是否有可能将 more_like_this 的结果与一些额外的搜索约束结合起来?
我有以下两个有效的 ES 查询:
POST /h/B/_search
{
"query": {
"more_like_this": {
"fields": [
"desc"
],
"ids": [
"511111260"
],
"min_term_freq": 1,
"max_query_terms": 25
}
}
}
返回
{
"took": 16,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"failed": 0
},
"hits": {
"total": 53,
"max_score": 3.2860293,
"hits": [
...
这很好,但我需要对单独工作的基础文档的其他字段指定额外的约束:
POST /h/B/_search
{
"query": {
"bool": {
"must": {
"match": {
"Kind": "Pen"
}
}
}
}
}
我很想将这两者合二为一,因为查询应说明:“查找与用 Pen 标记的项目相似的项目”。我尝试使用嵌套查询进行跟踪,但这给了我一些错误:
POST /h/B/_search
{
"query": {
"more_like_this": {
"fields": [
"desc"
],
"ids": [
"511111260"
],
"min_term_freq": 1,
"max_query_terms": 25
},
"nested": {
"query": {
"bool": {
"must": {
"match": {
"Kind": "Pen"
}
}
}
}
}
}
}
我尝试了几种变体来组合这两个搜索条件,但到目前为止没有运气。 如果有经验的人能提供一些提示,将不胜感激。
谢谢
【问题讨论】:
标签: elasticsearch