Elasticsearch支持多种语言 [英] Elasticsearch for multiple language support

查看:130
本文介绍了Elasticsearch支持多种语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Elasticsearch 5.1.1.我有一个要在哪里索引多种语言的数据的要求.

I am using elasticsearch 5.1.1. I have a requirement where in I want to index data in multiple languages.

我使用了以下映射:

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

当我尝试将某些数据插入为:

when I try to insert some data as :

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
}

有人可以指出我这里有什么问题吗?

Can someone point me what is wrong here?

推荐答案

问题是 title 字段被声明为 string ,而您正在尝试访问 title.en 子字段,就像 title object 字段一样.您需要像这样更改映射,然后它才能起作用:

The problem is that the title field is declared as a string and you're trying to access the title.en sub-field like you would do if title was and object field. You need to change your mapping like this instead and then it will work:

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

这篇关于Elasticsearch支持多种语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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