Nate Uni
Nate Uni

Reputation: 943

ElasticSearch: analyzer on field must be set when search_analyzer is set

I have read about previous version of ES (< 2) where the "token_analyzer" key needs to be changed to "analyzer". But no matter what I do I am still getting this error:

"type": "mapper_parsing_exception",
"reason": "analyzer on field [email] must be set when search_analyzer is set"

Here is what I am passing into ES via a PUT function when I get the error:

{ 
    "settings": {
      "analysis": {
        "analyzer": {
          "my_email_analyzer": {
            "type": "custom",
            "tokenizer": "uax_url_email",
            "filter": ["lowercase", "stop"]
          }
        }
      }
    },
    "mappings" : {
        "uuser": {
            "properties": {
                "email": {
                  "type": "text",
                  "search_analyzer": "my_email_analyzer",
                  "fields": {
                    "email": { 
                      "type":  "text",
                      "analyzer": "my_email_analyzer"
                    }
                  }
                },
                "facebookId": {
                    "type": "text"
                },
                "name": {
                    "type": "text"
                },
                "profileImageUrl": {
                    "type": "text"
                },
                "signupDate": {
                    "type": "date"
                },
                "username": {
                    "type": "text"
                }
                ,
                "phoneNumber": {
                    "type": "text"
                }
            }

        }
    }
}

Any ideas what is wrong?

Upvotes: 4

Views: 3759

Answers (1)

Adam T
Adam T

Reputation: 1691

Because you have specified a search_analyzer for the field, you also have to specify the analyzer to be used at indexing time. For example, add this line under where you specify the search_analyzer:

"analyzer": "standard",

To give you this:

{ 
    "settings": {
      "analysis": {
        "analyzer": {
          "my_email_analyzer": {
            "type": "custom",
            "tokenizer": "uax_url_email",
            "filter": ["lowercase", "stop"]
          }
        }
      }
    },
    "mappings" : {
        "uuser": {
            "properties": {
                "email": {
                  "type": "text",
                  "search_analyzer": "my_email_analyzer",
                  "analyzer": "standard",
                  "fields": {
                    "email": { 
                      "type":  "text",
                      "analyzer": "my_email_analyzer"
                    }
                  }
                },
                "facebookId": {
                    "type": "text"
                },
                "name": {
                    "type": "text"
                },
                "profileImageUrl": {
                    "type": "text"
                },
                "signupDate": {
                    "type": "date"
                },
                "username": {
                    "type": "text"
                }
                ,
                "phoneNumber": {
                    "type": "text"
                }
            }

        }
    }
}

See also: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html

Upvotes: 7

Related Questions