ElasticSearch:设置search_analyzer时,必须在字段上设置Analyzer

时间:2018-06-25 12:35:24

标签: elasticsearch

我已阅读有关ES(<2)的早期版本的信息,其中“ token_analyzer”键需要更改为“ analyzer”。但是,无论我做什么,我仍然会收到此错误:

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

这是我收到错误时通过PUT函数传递给ES的内容:

{ 
    "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"
                }
            }

        }
    }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

由于您为该字段指定了 search_analyzer ,因此您还必须指定要在建立索引时使用的 analyzer 。例如,将以下行添加到您指定search_analyzer的位置:

"analyzer": "standard",

给你这个:

{ 
    "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"
                }
            }

        }
    }
}

另请参阅:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html