【问题标题】:ElasticSearch _suggest queries are case sensitive. Want them to be case insensitiveElasticSearch _suggest 查询区分大小写。希望他们不区分大小写
【发布时间】:2014-12-18 16:06:12
【问题描述】:

我目前正在使用此端点执行搜索并请求:

elasticserver.com/citysuggest/_suggest -d {
  "result": {
    "text": "Chicago",
    "completion": {
      "field": "autoCompleteName"
    }
}

这是我的索引映射:

{
    "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 1,
        "index": {
            "mapper": {
                "dynamic": false
            }
        },
        "analysis": {
            "analyzer": {
                "str_search_analyzer": {
                    "tokenizer": "standard",
                    "filter": ["standard", "str_delimiter", "asciifolding", "porter_stem"]
                },
                "str_index_analyzer": {
                    "tokenizer": "standard",
                    "filter": ["standard", "str_delimiter", "asciifolding", "porter_stem"],
                    "char_filter": "html_strip"
                }
            },
            "filter": {
                "str_delimiter": {
                    "type": "word_delimiter",
                    "generate_word_parts": true,
                    "catenate_words": true,
                    "catenate_numbers": true,
                    "catenate_all": true,
                    "split_on_case_change": true,
                    "preserve_original": true,
                    "split_on_numerics": true,
                    "stem_english_possessive": true
                }
            }
        }
    },
    "mappings": {
        "city": {
            "_source": {
                "enabled": false
            },
            "dynamic": false,
            "properties": {
                "_all": {
                    "enabled": false
                },
                "autoCompleteName": {
                    "type": "completion",
                    "index_analyzer": "str_index_analyzer",
                    "search_analyzer": "str_search_analyzer"
                }
            }
        }
    }
}

当我搜索“芝加哥”时,它会返回预期的结果,因为它找到了芝加哥的匹配项,但是,当我搜索“芝加哥”时,它不会返回任何内容。我一生都无法弄清楚我需要更改什么以使搜索不区分大小写。如果用户键入“ChiCAgO”,它应该返回我的芝加哥结果,而我什么也得不到。

为了测试我的分析器,我运行了这个:

elasticserver.com/citysuggest/_analyze?text=ChicaGo&pretty

我得到了看起来像正确标记的值。

{
  "tokens": [
    {
      "token": "chicago",
      "start_offset": 0,
      "end_offset": 7,
      "type": "<ALPHANUM>",
      "position": 1
    }
  ]
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您只需将lowercase token filter 添加到分析仪即可。

     "analysis": {
         "analyzer": {
             "str_search_analyzer": {
                 "tokenizer": "standard",
                 "filter": ["standard", "str_delimiter", "asciifolding", "porter_stem", "lowercase"]
             },
             "str_index_analyzer": {
                 "tokenizer": "standard",
                 "filter": ["standard", "str_delimiter", "asciifolding", "porter_stem", "lowercase"],
                 "char_filter": "html_strip"
             }
         },
         "filter": {
             "str_delimiter": {
                 "type": "word_delimiter",
                 "generate_word_parts": true,
                 "catenate_words": true,
                 "catenate_numbers": true,
                 "catenate_all": true,
                 "split_on_case_change": true,
                 "preserve_original": true,
                 "split_on_numerics": true,
                 "stem_english_possessive": true
             }
         }
     }
    

    您的测试用例有效,因为您没有指定分析器,请尝试:

    curl -XGET 'localhost:9200/citysuggest/_analyze?analyzer=str_index_analyzer&text=ChicaGo&pretty'
    

    【讨论】:

    • 我认为标准包括小写?
    • 标准 analyzer 包含小写术语过滤器,但标准标记器和标准标记过滤器不包含。
    • 这是我听过的最愚蠢的事情。对于 ElasticSearch 文档中的文本量,它确实很糟糕。感谢您的信息,我会试一试!
    猜你喜欢
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 2013-04-25
    相关资源
    最近更新 更多