【问题标题】:What filter should i use to match the exact term/s inside a string?我应该使用什么过滤器来匹配字符串中的确切术语/s?
【发布时间】:2016-06-21 16:50:03
【问题描述】:

我正在使用 ElasticSearch 2.3.1。

我需要创建一个查询来检查文本中是否存在特定术语(单词或单词列表)。基本上类似于 like 运算符。

如果我使用 bool/must/match 过滤器,我可以按分数对文档进行排序,但我必须删除没有我需要搜索的所有术语的文档。

目前我正在使用 2gram,这是映射...

{
    "settings": {
        "analysis": {
            "filter": {             
                "2gramsto3_filter": {
                    "type":     "ngram",
                    "min_gram": 2,
                    "max_gram": 3
                }                
            },        
            "analyzer": {
                "2gramsto3": {
                    "type":      "custom",
                    "tokenizer": "standard",
                    "filter":   [
                        "lowercase",
                        "2gramsto3_filter"
                    ]
                }
            }
        }
    },  
    "mappings": {
        "agents": {
            "properties": {                             
                "cv": {
                    "type": "string",
                    "analyzer": "2gramsto3"                 
                }
        }
    }
}

但正如我在上面所写的,所有术语都必须在文本中,而不只是一个二元组。

【问题讨论】:

    标签: java elasticsearch


    【解决方案1】:

    如果您需要通过特定的一组词进行匹配,那么bool/must/match_phrase 可能比bool/must/match 更合适

    可以在文档的“入门”部分找到有关此内容的快速参考,您可以在此处找到:https://www.elastic.co/guide/en/elasticsearch/reference/current/_executing_searches.html:

    来自以上来源:

    此示例是 match (match_phrase) 的变体,它返回地址中包含短语“mill lane”的所有帐户:

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
    {
      "query": { "match_phrase": { "address": "mill lane" } }
    }'
    

    更多来自 ES 文档的细节可以在这个位置找到:https://www.elastic.co/guide/en/elasticsearch/reference/current/_executing_searches.html

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-22
    相关资源
    最近更新 更多