I'm using elasticsearch-rails (elasticsearch-model) gem and I'm getting a bit confused about how the model-dsl ultimately translates into an index configuration.
I'm having the following code to directly set up the index, and it works fine:
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"
}
}
}
}
However, when I (try to) do the same in the model, I get an error:
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
Error message:
MapperParsingException[Failed to parse mapping [matchable]: Field [_all] is defined twice in [matchable]]; nested: IllegalArgumentException[Field [_all] is defined twice in [matchable]];
It would be already helpful If I could bring elasticsearch-model (oder elasticsearch) to show me the entire request send to elasticsearch when creating that index.
Thank you for any suggestions :)