【问题标题】:Elasticsearch searching multi fieldsElasticsearch 搜索多个字段
【发布时间】:2018-12-22 02:53:34
【问题描述】:

我想就我的搜索要求寻求您的帮助或任何建议,因为我只是 elastisearch 的新手。这是我的 Elastisearch 索引详细信息:

_index               _type         _score     subs_name     subs_type
substation index     substation    1          Ad Diraz      loop 33
substation index     substation    1          Al Bareh      city 66 
substation index     substation    1          Budaiya       loop 33
substation index     substation    1          Galali        city 66

现在,我想搜索 subs_name 和 sub_type 之间的任何单词:

  1. 如果我搜索 diraz loop,我会得到 Ad Diraz, loop 33 的搜索结果
  2. 如果我搜索 loop diraz,我会得到 Ad Diraz, loop 33 的搜索结果
  3. 如果我搜索 bareh 66,我会得到 Al Bareh, city 66 的搜索结果
  4. 如果我搜索 Galali,我会得到 Galali, city 66 的搜索结果 最后
  5. 如果我搜索 Budaiya loop,它会给出 Budaiya, loop 33 的搜索结果

我尝试了下面的 elastisearch 查询,但它只适用于搜索号。 4

{"from": 0, "size": max_result,
    "query": {
    "multi_match": {
          "fields": ['subs_name', 'subs_type'],
          "query": search_this_query,
           "type": "phrase_prefix"
                   }
             }
}

任何有关使用什么弹性搜索查询的帮助将不胜感激。提前致谢!

【问题讨论】:

    标签: elasticsearch search indexing field


    【解决方案1】:

    如果您的两个字段的类型是字符串/文本并使用相同的分析器,那么您应该为此查询使用 cross_fields 类型

    GET /_search
    {
      "query": {
        "multi_match" : {
          "query":      "diraz loop",
          "type":       "cross_fields",
          "fields":     [ "subs_name","subs_type"]
         "operator":   "and"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-06
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      相关资源
      最近更新 更多