2

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 :)

trueunlessfalse
  • 1,163
  • 10
  • 16
  • Why are you trying to create `_all` field? `_all` is a special reserved field in every elasticsearch index to which fields from your mapping can be added/removed to query a group of fields at one shot. Trying using `indexes :dummy_field, ...` instead of `indexes :_all` as it might be conflicting with the reserved _all field. More ref here for [_all](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html) – Varun Natraaj Apr 27 '16 at 02:08

0 Answers0