Home > Software engineering >  cannot create custom analyzer elaticsearch
cannot create custom analyzer elaticsearch

Time:11-24

I'm trying to create a custom analyzer in elasticsearch. here is the analyzer

{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer" : "standard",
          "filter" : ["custom_stopper", "custom_stems", "custom_synonyms"]
        },
        "filter" : {
            "custom_stopper" : {
                "type" : "stop",
                "stopwords_path" : "analyze/stopwords.txt"
            },
            "custom_stems" : {
                "type" : "stemmer_override",
                "rules_path" : "analyze/stem.txt"
            },
            "custom_synonyms" : {
                "type" : "synonyms",
                "synonyms_path" : "analyze/synonym.txt"

            }
        }
        }
      }
    }
  }

but it throwing error

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "analyzer [filter] must specify either an analyzer type, or a tokenizer"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "analyzer [filter] must specify either an analyzer type, or a tokenizer"
    },
    "status": 400
}

What I'm doing wrong here?

CodePudding user response:

The filter must be on the same level with analyzer.

The structure looks somehow like this:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "char_filter": [
            "custom_stopper",
            "custom_stems",
            "custom_synonyms"
          ]
        }
      },
      "filter": {
        "custom_stopper": {
          "type": "stop",
          "stopwords_path": "analyze/stopwords.txt"
        },
        "custom_stems": {
          "type": "stemmer_override",
          "rules_path": "analyze/stem.txt"
        },
        "custom_synonyms": {
          "type": "synonyms",
          "synonyms_path": "analyze/synonym.txt"
        }
      }
    }
  }
}
  • Related