【问题标题】:ElasticSearch what analyzer should be used for searching for both url fragment and exact url pathElasticSearch 应该使用什么分析器来搜索 url 片段和确切的 url 路径
【发布时间】:2013-10-02 21:03:12
【问题描述】:

我想将 uri 存储在映射中,并希望通过以下方式使其可搜索:

  • 完全匹配(即,如果我存储:http://stackoverflow.com/questions,然后查找术语 http://stackoverflow.com/questions 会检索项目。

  • Bit like letter tokenizer 所有“单词”都应该是可搜索的。因此,搜索questionsstackoverflowcom 将返回http://stackoverflow.com/questions

  • 正在寻找“.”或 '/' 分隔的 url 片段应该仍然可以搜索。因此,搜索stackoverflow.com 将返回http://stackoverflow.com/questions

  • 应该不区分大小写。 (如小写)

  • html://htmls://www. 等对于搜索是可选的。因此,搜索http://stackoverflow.comstackoverflow.com 将返回http://stackoverflow.com/questions

也许解决方案应该是链接标记器或类似的东西。我对 ES 很陌生,所以这可能是一个微不足道的问题。 那么我应该使用/构建什么样的分析器来实现这个功能呢?

任何帮助将不胜感激。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    你是绝对正确的。您需要将字段类型设置为multi_field,然后为每个场景创建分析器。然后,您可以在核心上执行multi_match 查询:

    =============type properties===============
    {
        "fun_documents": {
            "properties": {
                "url": {
                    "type": "multi_field",
                    "fields": {
                        "keyword": {
                            "type": "string",
                            "analyzer": "keyword"
                        },
                        "alphanum_only": {
                            "type": "string",
                            "analyzer": "my_custom_alpha_num_analyzer"
                        },
                        {
                            "etc": "etc"
                        }
                    }
                }
            }
        }
    }
    
    ==================query=====================
    {
        "query": {
            "multi_match": {
                "query": "stackoverflow",
                "fields": [
                    "url.keyword",
                    "url.alphanum_only",
                    "url.optional_fun"
                ]
            }
        }
    }
    

    请注意,您可以使用 multi_field 别名并重复使用相同的名称,但这是简单的演示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-17
      • 2014-02-25
      • 1970-01-01
      • 2010-11-24
      • 2014-02-15
      • 2013-07-09
      • 2019-11-10
      • 2023-03-25
      相关资源
      最近更新 更多