Elasticsearch 多语言支持

Elasticsearch for multiple language support

我正在使用 elasticsearch 5.1.1。 我有一个要求,我想用多种语言索引数据。

我使用了以下映射:

放置http://localhost:9200/movies

{
  "mappings": {
    "title": {
      "properties": {
        "title": { 
          "type": "string",
          "fields": {
            "de": { 
              "type":     "string",
              "analyzer": "german"
            },
            "en": { 
              "type":     "string",
              "analyzer": "english"
            },
            "fr": { 
              "type":     "string",
              "analyzer": "french"
            },
            "es": { 
              "type":     "string",
              "analyzer": "spanish"
            }
          }
        }
      }
    }
  }
}

当我尝试插入一些数据时:

POST http://localhost:9200/movies/movie/1

{
"title.en" :"abc123"
}

我收到以下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[IQ7CUTp][127.0.0.1:9300][indices:data/write/index[p]]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "[title] is defined as an object in mapping [movie] but this name is already used for a field in other types"
  },
  "status": 400
}

谁能告诉我哪里出了问题?

如我所见,您已将 title 定义为 typeproperty。 该错误似乎说明了这个问题。

从你的 post 电话中,我看到 type 电影。 您真的想要 title 作为类型吗? 您应该在电影类型中定义标题的映射。

问题是 title 字段被声明为 string 并且您正在尝试访问 title.en 子字段,就像您在 [=11= 时所做的那样] 和 object 字段。您需要像这样更改您的映射,然后它才会起作用:

{
  "mappings": {
    "title": {
      "properties": {
        "title": { 
          "type": "object",           <--- change this
          "properties": {             <--- and this
            "de": { 
              "type":     "string",
              "analyzer": "german"
            },
            "en": { 
              "type":     "string",
              "analyzer": "english"
            },
            "fr": { 
              "type":     "string",
              "analyzer": "french"
            },
            "es": { 
              "type":     "string",
              "analyzer": "spanish"
            }
          }
        }
      }
    }
  }
}