【问题标题】:How to apply the not_analyzed to a field如何将 not_analyzed 应用于字段
【发布时间】:2018-11-02 23:59:57
【问题描述】:

我正在尝试将 not_analyzed 添加到 url 字段。我尝试使用它给我的字段类型字符串 Failed to parse mapping [doc]: No handler for type [string] declared on field [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"

                    }
                }
            }
        }
    }

【问题讨论】:

  • 尝试:删除 index: not_analyzed 并将字段类型更改为关键字而不是文本
  • 如果我将此字段类型更改为关键字,在 Kibana 中的 url 字段不会显示在过滤器列表中。
  • 您是否刷新了字段列表? Kibana -> 管理 -> 索引模式(在 kibana 选项卡下)-> 右侧的小重新加载图标
  • 是的,我刷新了该领域的工作,谢谢。

标签: elasticsearch


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-02-18
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    相关资源
    最近更新 更多