我正在使用 elasticsearch-rails (elasticsearch-model) gem,我对 model-dsl 最终如何转换为索引配置感到有些困惑。
我有以下代码来直接设置索引,它工作正常:
require 'elasticsearch'
client = Elasticsearch::Client.new log: true
# edge_ngram settings
settings_with_ngram = {
"analysis": {
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 3,
"max_gram": 8,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"nGram_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
# item
client.indices.delete index: "test_matchables"
client.indices.create index: "test_matchables", body: {
settings: settings_with_ngram,
mappings: {
matchable: {
"_all": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
}
}
}
}
但是,当我(尝试)在模型中做同样的事情时,我得到一个错误:
elasticsearch_settings = {
index: {
number_of_shards: 1,
number_of_replicas: 0
},
analysis: {
filter: {
nGram_filter: {
type: "nGram",
min_gram: 3,
max_gram: 8,
token_chars: [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
analyzer: {
nGram_analyzer: {
type: "custom",
tokenizer: "whitespace",
filter: [
"lowercase",
"asciifolding",
"nGram_filter"
]
},
whitespace_analyzer: {
type: "custom",
tokenizer: "whitespace",
filter: [
"lowercase",
"asciifolding"
]
}
}
}
}
settings(elasticsearch_settings) do
mappings do
indexes :_all, analyzer: 'nGram_analyzer', search_analyzer: 'whitespace_analyzer'
end
end
错误信息:
MapperParsingException[Failed to parse mapping [matchable]: Field [_all] is defined twice in [matchable]]; nested: IllegalArgumentException[Field [_all] is defined twice in [matchable]];
如果我可以带上 elasticsearch-model(oder elasticsearch)来向我展示在创建该索引时发送到 elasticsearch 的整个请求,那将会很有帮助。
谢谢你的任何建议:)