Elasticsearch使用数组字段索引multi_field [英] Elasticsearch indexing multi_field with array field

查看:89
本文介绍了Elasticsearch使用数组字段索引multi_field的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Elasticsearch的新手,我正在尝试使用 string stringsarray 字段创建多字段索引.使用 string 字段都可以很好地工作,但是当我尝试在数组中获取某些结果时,它会返回一个空值.

I'm new to elasticsearch and I'm trying to create a multi_field index with string and array of strings fields. With the string fields it's all working great but when I try to get some results when they are inside an array, it returns an empty one.

我的数据:

{
  "string_field_one": "one",
  "string_field_two": "two",
  "array_of_strings_field": [
     "2010", "2011", "2012", "2013"
  ]
}

映射:

{
    "string_field_one" : {
        "type" : "string",
        "analyzer": "snowball",
         "copy_to": "group"
     },
    "string_field_two" : {
        "type" : "string",
        "analyzer": "snowball",
         "copy_to": "group"
     },
    "array_of_strings_field" : {
         "type" : "string",
         "analyzer": "keyword",
         "copy_to": "group"
    }
    "group" : {
        "type": "multi_field"
    }
}

搜索:

 "body": {
          "query": {
              "multi_match": {
                  "query": "one two 2010",
                  type: "cross_fields",
                  operator: "and",
                  fields: [
                      "string_field_one",
                      "string_field_two",
                      "array_of_strings_field",
                      "group"
                  ]
              }
          }
      }

期望:

  • one two 2010 进行搜索应返回结果
  • 一二进行搜索应返回结果
  • 一两个2010 进行搜索应返回结果
  • 通过两个2008 进行搜索不应返回结果
  • Searching by one, two, or 2010 should return the result
  • Searching by one two should return the result
  • Searching by one two 2010 should return the result
  • Searching by one two 2008 should not return the result

我想念什么?

推荐答案

Cross_fields约束所有字段应具有相同的 query_string 对于上述情况:

Cross_fields has the constraint all fields should have the same search analyzer or rather all the query terms should occur in fields with same search analyzer. Which is not the case here. You would need to use query_string for the above case:

示例:

"body": {
           "query": {
              "query_string": {
                  "query": "one two 2010",
                  "default_operator": "AND",
                  "fields": [
                      "string_field_one",
                      "string_field_two",
                      "array_of_strings_field",
                      "group"
                  ]

              }
          }
   }

这篇关于Elasticsearch使用数组字段索引multi_field的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆