更像是这种弹性搜索

Glo*_*ior 2 elasticsearch morelikethis

我试图使用elasticsearch的http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html#query-dsl-mlt-为相关项目做一个简单的POC .查询,

但我没有得到如何使用增强功能,以便我的文档中的重要字段在最终输出中承载更多权重.另外,我如何应用更多像此查询的提升,以便最近的文档更重要.

谢谢.

kee*_*ety 9

如果文档更像是特定文档或者匹配是在特定字段上,那么实现特定提升的一种方法是,您可以使用多个mlt查询并 根据您是否需要"sum of" 将它们包装在should子句(bool)/ dis_max中得分时/"最大"逻辑:

使用dis_max的示例将是:

POST  test_index/_search?explain=true
{
    "fields": [
       "field1",
       "field2"
    ], 
    "query": { 
        "dis_max": {
           "queries": [
               {
                "more_like_this" : {
                    "fields" : ["field1"],
                    "like_text" : "this is  some text",
                    "min_term_freq" : 1,
                    "max_query_terms" : 2,
                    "boost": 20
                }
               },
               {
                "more_like_this" : {
                    "fields" : ["field2"],
                    "like_text" : "this is some other text",
                    "min_term_freq" : 1,
                    "max_query_terms" : 2,
                    "boost": 20
                }
               }
            ]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 在上面的例子中,我使用了'dis_max`,它通过分配两个`more_like_this`子句的得分的'max`来对文档进行评分.如果您希望为文档分配一个得分,该得分是各个`more_like_this`子句得分的总和,您需要将其包含在`bool`查询中.请参阅此[主题](http://stackoverflow.com/questions/35440312/how-do-i-include-a-sum-clause-for-two-more-like-this-queries/35442494#comment58587023_35442494)例 (4认同)