在弹性搜索中定义字符串字段数组

Define array of strings field in elastic search

如何定义接受字符串数组的字段,例如 ["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
}

不允许在嵌套映射中使用单个值。来自docs——系统

allows arrays of objects to be indexed in a way that they can be queried independently of each other.

也就是说,

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"
    }
  ]
}

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