如何在ES中提升should子句的某些词组?

问题描述 投票:0回答:1

我使用的是下面的查询。

{
    "_source": [
        "title",
        "bench",
        "id_",
        "court",
        "date",
        "content"
    ],
    "size": 15,
    "from": 0,
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "query": "london",
                        "fields": [
                            "title",
                            "content"
                        ]
                    }
                }
            ],
            "should": [
                {
                    "multi_match": {
                        "query": "London is a beautiful city and has a lot of amazing landmarks. I love the Thames!",
                        "fields": [
                            "title",
                            "content^2"
                        ],
                        "operator": "or"
                    }
                }
            ]
        }
    },
    "highlight": {
        "pre_tags": [
            "<tag1>"
        ],
        "post_tags": [
            "</tag1>"
        ],
        "fields": {
            "content": {}
        },
        "number_of_fragments": 5,
        "fragment_size": 300
    }
}

这个查询的合理性是,伦敦这个词必须存在,而那些在should查询中的词组应该只是提升分数。我想做的是,在should查询中,我想提升短语beautiful city和单词Thames的分数。请问我该怎么做呢?

PS:内容和标题是标准文本字段,没有应用分析器。

敬告

elasticsearch elasticsearch-5
1个回答
1
投票

你可以在should query中添加多个子句

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "london",
            "fields": [
              "title",
              "content"
            ]
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "query": "beautiful city",
            "fields": [
              "title",
              "content^2"
            ],
            "type": "phrase"
          }
        },
        {
          "multi_match": {
            "query": "Thames",
            "fields": [
              "title",
              "content^2"
            ]
          }
        }
      ]
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.