Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify an analyzer while creating an index in ElasticSearch

Tags:

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.

like image 757
Alfe Avatar asked Aug 14 '13 16:08

Alfe


People also ask

How do I add an analyzer to an existing index Elasticsearch?

You can only define new analyzers on closed indices. To add an analyzer, you must close the index, define the analyzer, and reopen the index.

What is the default analyzer Elasticsearch?

By default, Elasticsearch uses the standard analyzer for all text analysis. The standard analyzer gives you out-of-the-box support for most natural languages and use cases. If you chose to use the standard analyzer as-is, no further configuration is needed.

What is an analyzer in Elasticsearch?

In a nutshell an analyzer is used to tell elasticsearch how the text should be indexed and searched. And what you're looking into is the Analyze API, which is a very nice tool to understand how analyzers work. The text is provided to this API and is not related to the index.


1 Answers

"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

like image 136
Scott Rice Avatar answered Oct 11 '22 06:10

Scott Rice