Error: "mapper_parsing_exception", "reason": "analyzer [my_custom_analyzer] not found for field [topic_content]"

Hi, I'm building an application that uses elasticsearch to store textual data from various csv inputs. i'm running the backend with nodejs and python so the indexing and uploading of data is done in elasticsearch-py. I'm having some errors with that. In the first part of that, I create my own mapping and analyzer. This is how they look like:

{
  "mappings": {
    "test": {
      "properties": {
        "age": {
          "type": "long"
        },
        "topic_content": {
          "type": "string",
          "analyzer": "my_custom_analyzer",
          "term_vector": "yes"
        },
        "name": {
          "type": "string",
          "analyzer": "my_custom_analyzer",
          "term_vector": "yes"
        }
      }
    }
  },
  "analysis": {
    "analyzer": {
      "my_custom_analyzer": {
        "filter": [
          "lowercase",
          "kstem"
        ],
        "char filter": [
          "html_strip"
        ],
        "type": "custom",
        "tokenizer": "classic"
      }
    }
  }
}

I then upload the data using the es.indices.create method in python. This is where I'm getting an error that my analyzer doesn't exist but I can see it being created so I'm confused on why I am getting this error.

es.indices.create(index = project.uid, ignore=400, body=settings)

Edit: settings above refers to the object containing my mappings and my analyzer.

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "analyzer [my_custom_analyzer] not found for field [topic_content]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [test]: analyzer [my_custom_analyzer] not found for field [topic_content]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "analyzer [my_custom_analyzer] not found for field [topic_content]"
    }
  },
  "status": 400
}

Hi,

You should put "analysis" into "settings", like the following:

{
  "mappings": {
   ...
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "filter": [
            "lowercase",
            "kstem"
          ],
          "char filter": [
            "html_strip"
          ],
          "type": "custom",
          "tokenizer": "classic"
        }
      }
    }
  }
}

See: https://www.elastic.co/guide/en/elasticsearch/guide/current/configuring-analyzers.html

4 Likes

oh! I must have gotten confused. So that entire structure should be declared as the body variable? (I mean the body = settings in es.indices.create)

Ah, yes.
I added "settings" before "analysis" in your body variable.
"analysis" property should be IN "settings" property.

Does it make sense?

2 Likes

Yes it does!! Thank you for correcting me! I couldn't figure out what was going on for the entire weekend :sweat_smile: