一尘不染

如何为两个more_like_this查询包含sum子句?

elasticsearch

我想在两个查询中 求和* 而不是在以下查询中使用 dis_max 。如何修改此查询来实现? *more_like_this

POST /ucberkley/docs/_search
{
  "fields": [
    "Category"
  ],
  "size": 1500,
  "query": {
    "dis_max": {
      "queries": [{
        "more_like_this": {
          "fields": [
            "PRIMARY_CONTENT_EN"
          ],
          "ids": [
            173161
          ],
          "min_term_freq": 1,
          "max_query_terms": 2,
          "boost": 2
        }
      }, {
        "more_like_this": {
          "fields": [
            "PRIMARY_CONTENT_EN"
          ],
          "ids": [
            175277
          ],
          "min_term_freq": 1,
          "max_query_terms": 2,
          "boost": -1
        }
      }]
    }
  }
}

阅读 406

收藏
2020-06-22

共1个答案

一尘不染

实现此目的的一种方法是通过使用子句的布尔查询should

例:

 "query": {
    "bool": {
      "disable_coord" : "true",
      "should": [{
        "more_like_this": {
          "fields": [
            "PRIMARY_CONTENT_EN"
          ],
          "ids": [
            173161
          ],
          "min_term_freq": 1,
          "max_query_terms": 2,
          "boost": 1
        }
      }, {
        "more_like_this": {
          "fields": [
            "PRIMARY_CONTENT_EN"
          ],
          "ids": [
            175277
          ],
          "min_term_freq": 1,
          "max_query_terms": 2,
          "boost": -1
        }
      }]
    }
  }
2020-06-22