【问题标题】:ElasticSearch Querystring Query Wildcard on query with multiple tokensElasticSearch Querystring 查询通配符查询具有多个令牌
【发布时间】:2015-10-09 13:31:45
【问题描述】:

例如,我有一条内容为“FileV2UpdateRequest”的记录,根据我的分析器,它会将记录分解为令牌:

  • 文件
  • 2
  • 更新请求

我希望能够在“query_string”查询中搜索filev2update* 以找到它,但无论出于何种原因,* 都不会像它应该那样尝试找到“updaterequest”的其余部分。

如果我输入查询filev2 update*,它会返回结果。

在不需要空间的情况下,我能做些什么来完成这项工作吗?

我已尝试将 auto_generate_phrase_queries 设置为 true,但这也无法解决问题。似乎当您添加通配符时,它会将整个输入视为一个标记,而不仅仅是查看通配符所接触的标记。

如果我添加 analyze_wildcard 并将其设置为 true,它会尝试将 * 放在查询中的每个标记上。 costv* 2* 添加*

【问题讨论】:

    标签: elasticsearch wildcard


    【解决方案1】:

    我认为您可以通过使用word_delimiter 为您的内容编制索引来更改索引过滤器Compound Word Token Filter

    如果使用这个过滤器

    FileV2UpdateRequest会被解析为token:

    {
        "tokens": [{
            "token": "File",
            "start_offset": 0,
            "end_offset": 4,
            "type": "word",
            "position": 1
        }, {
            "token": "V",
            "start_offset": 4,
            "end_offset": 5,
            "type": "word",
            "position": 2
        }, {
            "token": "2",
            "start_offset": 5,
            "end_offset": 6,
            "type": "word",
            "position": 3
        }, {
            "token": "Update",
            "start_offset": 6,
            "end_offset": 12,
            "type": "word",
            "position": 4
        }, {
            "token": "Request",
            "start_offset": 12,
            "end_offset": 19,
            "type": "word",
            "position": 5
        }]
    }
    

    对于搜索内容,您还需要使用 word_delimiter 作为过滤器,而不使用 wild_card

    filev2update 将被分析为令牌:

    {
        "tokens": [{
            "token": "file",
            "start_offset": 0,
            "end_offset": 4,
            "type": "word",
            "position": 1
        }, {
            "token": "V",
            "start_offset": 4,
            "end_offset": 5,
            "type": "word",
            "position": 2
        }, {
            "token": "2",
            "start_offset": 5,
            "end_offset": 6,
            "type": "word",
            "position": 3
        }, {
            "token": "update",
            "start_offset": 6,
            "end_offset": 12,
            "type": "word",
            "position": 4
        }]
    }
    

    【讨论】:

    • 我确实有一些情况,我有一个像 File_V2_Update 这样的例子,我希望 _ 在搜索中很重要......单词分隔​​符不会忽略这些吗?
    • 它会忽略_,但你为什么要搜索_?
    • 因为如果我有 File_V2_Update 和 FileV2Update 我希望它们是可区分的
    猜你喜欢
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    相关资源
    最近更新 更多