弹性搜索中定义字符串字段的字段

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

如何定义一个接受诸如[“ A”,“ B”,“ C”之类的字符串数组的字段。

我已尝试执行以下操作:在索引中创建了一个字段:

    {
      "properties": 
      {
        "date": {"type": "date"},
        "imageUrls": { "type": "nested" },
        }
    }

我写文档

..../_doc/1

方法:POST

正文:

{
    "imageUrls": ["A", "B", "C"]
}

总是出现此错误:

{
    "error": {
        "root_cause": [
            {
                "type": "mapper_parsing_exception",
                "reason": "object mapping for [imageUrls] tried to parse field [null] as object, but found a concrete value"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "object mapping for [imageUrls] tried to parse field [null] as object, but found a concrete value"
    },
    "status": 400
}
elasticsearch amazon-elastic-beanstalk elastic-stack
1个回答
0
投票

嵌套映射中的单个值是不允许的。从docs-系统

允许以彼此可以独立查询的方式对对象数组进行索引。

也就是说,

PUT ahm
{
  "mappings": {
    "properties": {
      "date": {
        "type": "date"
      },
      "imageUrls": {
        "type": "nested",
        "properties": {
          "url": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          }
        }
      }
    }
  }
}

然后

POST ahm/_doc
{
  "imageUrls": [
    {
      "url": "A"
    },
    {
      "url": "B"
    },
    {
      "url": "C"
    }
  ]
}

这是非常荒谬的,但是如果将更多属性添加到数组对象,它将开始变得有意义。

© www.soinside.com 2019 - 2024. All rights reserved.