首页 > 解决方案 > 如何在 Elastic Search 中从多个查询(查询 1 中的 x 记录和查询 2 中的 y 记录)中获取有限的结果

问题描述

我有两个不同的查询,我想从它们中得到一个组合结果,即来自查询 1 的 x 条记录和来自查询 2 的 y 条记录。我该怎么做?

目前我正在使用以下查询:

 **{ "bool" : {
  "should" : [
   {
    "multi_match" : {
      "query" : "indea",
      "fields" : [
        "admin^1.0",
        "city^1.0",
        "country^1.0"
      ],
      "type" : "best_fields",
      "operator" : "OR",
      "slop" : 0,
      "fuzziness" : "2",
      "prefix_length" : 0,
      "max_expansions" : 50,
      "zero_terms_query" : "NONE",
      "auto_generate_synonyms_phrase_query" : true,
      "fuzzy_transpositions" : true,
      "boost" : 1.0
     }
    },
   {
    "multi_match" : {
      "query" : "Maharashtra",
      "fields" : [
        "admin^1.0"
      ],
      "type" : "best_fields",
      "operator" : "OR",
      "slop" : 0,
      "prefix_length" : 0,
      "max_expansions" : 50,
      "zero_terms_query" : "NONE",
      "auto_generate_synonyms_phrase_query" : true,
      "fuzzy_transpositions" : true,
      "boost" : 1.0
      }
   }
 ],
 "adjust_pure_negative" : true,
 "boost" : 1.0
  }
}**

标签: javaelasticsearch

解决方案


推荐阅读