我正在使用elasticsearch 5.1.1。 我有一個要求,我想在多種語言索引數據。支持多種語言的Elasticsearch
我用下面的映射:
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"
}
}
}
}
}
}
}
當我嘗試插入一些數據:
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
}
有人能指出我這裏有什麼問題?
感謝Val和@ christinabo,您的兩個解決方案都能正常工作。 基本上我想用「電影」作爲類型。現在我可以發佈數據。 \t \t 現在我想測試,如果我的分析儀確實對不同的語言,我怎麼能做到這一點。 現在它接受我發佈並返回搜索的白名單。 – SSG
在字段中設置英文分析器不會阻止您將西班牙文內容編入索引,因此ES會接受您在所有語言特定字段中發佈的任何字符串。最好的測試方法是打開[分析API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html),看看你的文本是如何分析的。 – Val
用'spanish'分析器分析'summer'沒有什麼不對。 ES不會翻譯你的內容。 – Val