在 Elasticsearch 中,我可以设置语言特定的多字段吗?

In Elasticsearch, can I set language-specific multi-fields?

是否可以使用多字段设置查询多语言字段?

考虑这个映射:

PUT multi_test
{
  "mappings": {
    "data": {
      "_field_names": {
        "enabled": false
      },
      "properties": {
        "book_title": {
          "type": "text",
          "fields": {
            "english": {
              "type": "text",
              "analyzer": "english"
            },
            "german": {
              "type": "text",
              "analyzer": "german"
            },
            "italian": {
              "type": "text",
              "analyzer": "italian"
            }
          }
        }
      }
    }
  }
}

我尝试了以下方法,但它不起作用:

PUT multi_test/data/1
{
  "book_title.english": "It's good",
  "book_title.german": "Das gut"
}

该错误似乎表明我正在尝试添加新字段:

{ "error": { "root_cause": [ { "type": "mapper_parsing_exception", "reason": "Could not dynamically add mapping for field [book_title.english]. Existing mapping for [book_title] must be of type object but found [text]." } ], "type": "mapper_parsing_exception", "reason": "Could not dynamically add mapping for field [book_title.english]. Existing mapping for [book_title] must be of type object but found [text]." }, "status": 400 }

我做错了什么?

如果我的方法行不通,什么是更好的方法?

问题是您正在为 字段使用 using 字段 book_title

在您的用例中,映射应如下所示

放置multi_test

{
  "mappings": {
    "data": {
      "_field_names": {
        "enabled": false
      },
      "properties": {
        "book_title": {
          "properties": {
            "english": {
              "type": "text",
              "analyzer": "english"
            },
            "german": {
              "type": "text",
              "analyzer": "german"
            },
            "italian": {
              "type": "text",
              "analyzer": "italian"
            }
          }
        }
      }
    }
  }
}

这会将 book_title 定义为对象类型,您可以在 book_title

下添加具有不同数据的多个字段