我想在 Elastic Search 中使用 More like this 查询来查找类似文档。但是,我需要过滤执行查询的文档。
示例如下:我想查找与 ID 为 123456 的博客类似但作者为 120 或作者 123 的博客项目。
当执行这个查询时,我从所有作者那里得到了类似的博客,因此没有被过滤......
{
"query":{
"more_like_this" : {
"fields" : ["body" ],
"docs" : [
{
"_id" : "123456"
}
],
"percent_terms_to_match" : 0.4,
"min_term_freq" : 1
}
}
},
"filter":{
"and":[
{
"type":{ "value":"blog" }
},
{
"terms":{ "authorId": ["120", "123"] }
}
]
}
}
最佳答案
像这样尝试过滤查询:
{
"query": {
"filtered": {
"query": {
"more_like_this": {
"fields": [
"body"
],
"docs": [
{
"_id": "123456"
}
],
"percent_terms_to_match": 0.4,
"min_term_freq": 1
}
},
"filter": {
"and": [
{
"type": {
"value": "blog"
}
},
{
"terms": {
"authorId": [
"120",
"123"
]
}
}
]
}
}
}
}
希望对您有所帮助...!
关于elasticsearch - 如何在 Elastic Search 中为更像这样的查询添加过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23960921/