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

时间:2016-02-16 18:27:41

标签: elasticsearch

我想在以下查询中使用 dis_max ,而不是在两个more_like_this查询中找到 sum 。如何修改此查询以实现该目标?

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
        }
      }]
    }
  }
}

1 个答案:

答案 0 :(得分:1)

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

示例:

 "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
        }
      }]
    }
  }