20

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.

Alfe
  • 56,346
  • 20
  • 107
  • 159

1 Answers1

28

"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

TotPeRo
  • 6,561
  • 4
  • 47
  • 60
Scott Rice
  • 2,430
  • 22
  • 18
  • 4
    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. – Scott Rice Aug 14 '13 at 18:05
  • 1
    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 ;) – Ted Avery Jan 13 '14 at 03:07