shantanuo
shantanuo

Reputation: 32304

Can not create an index

I tried to create test index exactly as shown in this answer...

Elasticsearch layered ordering

PUT /test
{
  "settings": {
    "analysis": {
      "analyzer": {
        "autocomplete": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "ngram"
          ]
        },
        "search_ngram": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": "lowercase"
        }
      },
      "filter": {
        "ngram": {
          "type": "ngram",
          "min_gram": 2,
          "max_gram": 15
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "text": {
          "type": "string",
          "index_analyzer": "autocomplete",
          "search_analyzer": "search_ngram",
          "index_options": "positions",
          "fields": {
            "not_analyzed_sorting": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
  }
}

But I get the error. If I remove these 2 lines, then I can create the index, but that will not return the correct results.

  "index_analyzer": "autocomplete",
  "search_analyzer": "search_ngram",

The error is:

{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "analyzer on field [text] must be set when search_analyzer is set"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "Failed to parse mapping [test3]: analyzer on field [text] must be set when search_analyzer is set",
      "caused_by": {
         "type": "mapper_parsing_exception",
         "reason": "analyzer on field [text] must be set when search_analyzer is set"
      }
   },
   "status": 400
}

I use sense extension of crome and my elasticsearch server is a hosted on Amazon ec2 instance.

I will like to know what is the correct way to create index as shown in that answer.

Upvotes: 0

Views: 172

Answers (1)

Priyansh Goel
Priyansh Goel

Reputation: 2660

Instead of

"index_analyzer": "autocomplete", 

Try:

"analyzer":"autocomplete"

And you can make your search_analyzer to be standard.

See this for similar usecase.

Upvotes: 1

Related Questions