如何将 not_analyzed 应用于字段

an_*_*her 1 elasticsearch

我正在尝试将 not_analyzed添加到 url 字段。我尝试使用它给我的字段类型字符串无法解析映射[doc]:没有在字段[url]上声明的类型[字符串]的处理程序,并且我用文本替换了类型,并且我得到了无法解析映射[doc]:无法将 [url.index] 转换为布尔异常。如何使提交的 url not_analyzed

 PUT /some_index
    {
        "settings": {
            "index": {
                "number_of_shards": 5,
                "number_of_replicas": 1,
                "refresh_interval": "60s",
                "analysis" : {
                  "analyzer" : {
                    "my_analyzer" : {
                        "tokenizer" : "standard",
                        "filter" : ["standard", "lowercase", "my_snow","asciifolding","english_stop"]
                    }
                  },
                  "filter" : {
                    "my_snow" : {
                        "type" : "snowball",
                        "language" : "Lovins"
                    },
                    "english_stop": {
              "type":        "stop",
              "stopwords":"_english_"
            }
                }
            }
            }
        },
        "mappings": {
            "doc": {
                "_source": {
                    "enabled": true
                },
                "properties": {
                    "content": {
                        "type": "text",
                        "index": "true",
                        "store": true,
                               "analyzer":"my_analyzer",
                                "search_analyzer": "my_analyzer"
                    },
                    "host": {
                        "type": "keyword",
                        "index": "true",
                        "store": true

                    },
                    "title": {
                        "type": "text",
                        "index": "true",
                        "store": true,
                                "analyzer":"my_analyzer",
                                "search_analyzer": "my_analyzer"

                    },
                    "url": {
                        "type": "text",
                        "index": "not_analyzed",
                         "store": true,
                        "search_analyzer": "my_analyzer"

                    }
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

小智 9

Elasticsearch 5.0 删除了该not_analyzed设置。取而代之的是,该string类型被分为两种:text哪个被分析,keyword哪个不被分析。阅读这篇博文了解更多内容:弦乐已死,弦乐万岁!

假设您运行的是 5.0+,则您的映射具有非法值。另外,它是冲突的:你说你不希望url被分析,但你指定了一个分析器:"search_analyzer": "my_analyzer"

如果您不想分析该字段,则应将 url 字段设置为与主机相同:

"url": {
    "type": "keyword"
}
Run Code Online (Sandbox Code Playgroud)

否则,创建类型text

"url": {
    "type": "text",
    "search_analyzer": "my_analyzer"
}
Run Code Online (Sandbox Code Playgroud)