elasticsearch - 如何将not_analyzed应用于字段

标签 elasticsearch

我正在尝试将 not_analyzed 添加到网址字段。我尝试使用字段类型字符串给它未能解析映射[doc]:没有在字段[url] 上声明类型[string]的处理程序,我用文本替换了该类型,但我得到了未能解析映射[ doc]:无法将[url.index]转换为boolean 异​​常。我怎样才能使归档的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"

                    }
                }
            }
        }
    }

最佳答案

Elasticsearch 5.0删除了not_analyzed设置。在其位置上,string类型分为两部分:已分析的text和未分析的keyword。在此博客文章上阅读更多信息:Strings are dead, long live strings!

假设您正在运行5.0+,则您的映射具有非法值。而且,这是冲突的:您说您不想分析url,但是您指定了一个分析器:"search_analyzer": "my_analyzer"
如果不想分析该字段,则应将url字段设置为与主机相同的设置:

"url": {
    "type": "keyword"
}

否则,输入text:
"url": {
    "type": "text",
    "search_analyzer": "my_analyzer"
}

关于elasticsearch - 如何将not_analyzed应用于字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53119521/

相关文章:

elasticsearch - 通过geo_point优先匹配结果,并在Elasticsearch中按最近位置排序

symfony - FOSElasticaBundle问题在cron作业中运行填充命令

elasticsearch - 如何使Logstash每天运行一次并在作业完成后自动停止

搜索索引 Windows SMB 文件共享的解决方案

linux - 没有显示Elasticsearch集群

c# - NopCommerce、C#、MVC、Elastic Search 多个参数

elasticsearch - 使用Java API获取 child 的 parent ID

python - 在 python Elasticsearch 中滚动不起作用

java - Elasticsearch - 在 Java 中实现完成建议(API 版本 5!)

java - Elasticsearch Java/Groovy API : how can I send JSON requests