【问题标题】:elasticsearch multiple size options for multiple indices多个索引的弹性搜索多个大小选项
【发布时间】:2021-03-04 22:35:17
【问题描述】:

我的目标:为 index1 返回 15 个结果,为其他索引返回 10 个结果

我的问题:由于“hotel_name”是最重要的字段,并且它只存在于第一个索引中,因此根据查询,响应只有来自 index1 的数据

请求 URL: "/index1,index2,index3/_search?size=25"

{
  "query": {
    "multi_match": {
      "query": "hotel",
      "type": "phrase_prefix",
      "fields": [
        "hotel_name^9",
        "country^8",
        "city^7",
        "destination^6",
        "state^5",
        "zone^4",
        "title^3",
        "description_short^2",
        "description^1"
      ]
    }
  }
}

编辑: @llermaly 回答后解决:

发帖请求:http://127.0.0.1:9200/_msearch

请求负载:

{"index":"index_1"}
{"size":30,"query":{"multi_match":{"query":"hotel","type":"phrase_prefix","fields":["hotel_name^8","country^7","city^6","destination^5","state^4","zone^3","description_short^2","description^1"]}}}
{"index":"index_2,index_2,index_3"}
{"size":10,"query":{"multi_match":{"query":"hotel","type":"phrase_prefix","fields":["country^8","city^7","destination^6","state^5","zone^4","title^3","description_short^2","description^1"]}}}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您不能在多索引 _search 查询上设置多个大小,但您可以使用 Multi Search API 并为每个索引查询设置不同的大小。

    GET _msearch
    {"index": "index1"}
    {
      "size": 15
      "query": {
        "multi_match": {
          "query": "hotel",
          "type": "phrase_prefix",
          "fields": [
            "hotel_name^9",
            "country^8",
            "city^7",
            "destination^6",
            "state^5",
            "zone^4",
            "title^3",
            "description_short^2",
            "description^1"
          ]
        }
      }
    }
    {"index": "index2"}
    {
      "size": 10
      "query": {
        "multi_match": {
          "query": "hotel",
          "type": "phrase_prefix",
          "fields": [
            "country^8",
            "city^7",
            "destination^6",
            "state^5",
            "zone^4",
            "title^3",
            "description_short^2",
            "description^1"
          ]
        }
      }
    }
    {"index": "index3"}
    {
      "size": 10
      "query": {
        "multi_match": {
          "query": "hotel",
          "type": "phrase_prefix",
          "fields": [
            "country^8",
            "city^7",
            "destination^6",
            "state^5",
            "zone^4",
            "title^3",
            "description_short^2",
            "description^1"
          ]
        }
      }
    }
    

    您可以使用Query Templates 来避免重复。

    【讨论】:

    • 谢谢@llermaly,这对我帮助很大。我在我的问题中添加了一个示例。
    • 然后您可以将此答案标记为正确:)
    猜你喜欢
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 2023-03-26
    • 2021-05-18
    相关资源
    最近更新 更多