简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM