0
votes

I would like to add anaylyser uax_url_email for search email field in elasticsearch document. However, I get the error.

Here is the code I am using to create this index

  {
        "user": {
          "aliases": {},
          "mappings": {
            "user": {
              "properties": {
                "created": {
                  "type": "date"
                },
                "email": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                }
              }
            }
          },
          "settings": {
            "index": {
              "number_of_shards": "5",
              "provided_name": "user",
              "creation_date": "1521016015646",
              "analysis": {
                "analyzer": {
                  "my_analyzer": {
                    "tokenizer": "my_tokenizer"
                  }
                },
                "tokenizer": {
                  "my_tokenizer": {
                    "type": "uax_url_email",
                    "max_token_length": "255"
                  }
                }
              },
              "number_of_replicas": "1",
              "uuid": "RS96V9gFQbG5UmoQ2R_gLA",
              "version": {
                "created": "6010099"
              }
            }
          }
        }
      }

PUT /user/_mapping/email

{
  "mappings": {
    "_doc": {
      "properties": {
        "email": { 
          "type": "text",
          "fields": {
            "my_analyzer": { 
              "email":     "text",
              "analyzer": "my_analyzer"
            }
          }
        }
      }
    }
  }
}

I got an error stating "root_cause":

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters:  [mappings : {_doc={properties={email={type=text, fields={my_analyzer={email=text, analyzer=my_analyzer}}}}}}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Root mapping definition has unsupported parameters:  [mappings : {_doc={properties={email={type=text, fields={my_analyzer={email=text, analyzer=my_analyzer}}}}}}]"
  },
  "status": 400
}

Nothing will be found. I want my analyzer and tokenizer work on email field any help will be highly appreciated

1

1 Answers

1
votes

This should work:

PUT /user/_mapping/user
{
  "properties": {
    "email": {
      "type": "text",
      "fields": {
        "my_analyzer": {
          "type": "text",
          "analyzer": "my_analyzer"
        }
      }
    }
  }
}

Your mistake was that you thought that the index type was _doc, but looking at your mapping, the index type is user. Basically, you have a user index with a user type.

The format of the command is PUT /[INDEX_NAME]/_mapping/[TYPE_NAME] {"properties:" { "[FIELD_TO_BE_UPDATED]": {....} } }.