How to specify an analyzer while creating an index in ElasticSearch

18,409

"analysis" goes in the "settings" block, which goes either before or after the "mappings" block when creating an index.

"settings": {
    "analysis": {
        "analyzer": {
            "alfeanalyzer": {
                "type": "pattern",
                "pattern": "\\s+"
            }
        }
    }
},
"mappings": {
    "alfedoc": { ... }
}

Here's a good complete, example: Example 1

Share:
18,409

Related videos on Youtube

Alfe
Author by

Alfe

http://www.alfe.de

Updated on August 04, 2020

Comments

  • Alfe
    Alfe over 3 years

    I'd like to specify an analyzer, name it, and use that name in a mapping while creating an index. I'm lost, my ES instance always returns me an error message.

    This is, roughly, what I'd like to do:

    "settings": {
      "mappings": {
        "alfedoc": {
          "properties": {
            "id": { "type": "string" },
            "alfefield": { "type": "string", "analyzer": "alfeanalyzer" }
          }
        }
      },
      "analysis": {
        "analyzer": {
          "alfeanalyzer": {
            "type": "pattern",
            "pattern":"\\s+"
          }
        }
      }
    }
    

    But this does not seem to work; the ES instance always returns me an error like

    MapperParsingException[mapping [alfedoc]]; nested: MapperParsingException[Analyzer [alfeanalyzer] not found for field [alfefield]];
    

    I tried putting the "analysis" branch of the dictionary at several places (inside the mapping etc.) but to no avail. I guess a working complete example (which I couldn't find up to now) would help me along as well. Probably I'm missing something rather basic.

  • Scott Rice
    Scott Rice over 10 years
    Yes, indeed, I forgot that last brace under "settings". So "settings" and "mappings" should be 2 separate blocks, and "analysis" should be included in the "settings" block.
  • Ted Avery
    Ted Avery over 10 years
    Thanks for the links, found what I needed! But the point where the mapping actually specifies which analyzers to use for a particular property is what I have had the hardest time finding examples of. It would be a great addition to your answer ;)