代码之家  ›  专栏  ›  技术社区  ›  Nate Uni

ElasticSearch:设置搜索分析器时必须设置Analyzer on字段

  •  1
  • Nate Uni  · 技术社区  · 6 年前

    我已经阅读了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 回复  |  直到 6 年前
        1
  •  4
  •   Adam T    6 年前

    因为你指定了 搜索分析器 对于字段,还必须指定 分析仪 在索引时使用。例如,在指定搜索分析器的位置下添加此行:

    "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