【问题标题】:ElasticSearch/Elastica: searching for exact term that includes "and" or other stopwordsElasticSearch/Elastica:搜索包含“and”或其他停用词的确切术语
【发布时间】:2013-04-07 02:28:34
【问题描述】:

我正在尝试让 ES QueryString 匹配其中包含“and”的搜索词,但到目前为止我尝试的所有方法(尝试不同的分析器、tokenziers、过滤器)都没有奏效。在 MySQL 方面,我想要的是:

WHERE field LIKE '%abbot and costello%'

我尝试了各种配置,这是我目前正在使用的(略有改进,它匹配“abbot”(带有尾随空格),但仍然不匹配任何带有“and”的东西:

$eI->create(array(
    'analysis' => array(
        'analyzer' => array(
            'indexAnalyzer' => array(
                'type' => 'custom',
                'tokenizer' => 'SQLedgeNGram',
                'filter' => array(
                    'lowercase',
                ),
            ),
            'searchAnalyzer' => array(
                'type' => 'custom',
                'tokenizer' => 'SQLedgeNGram',
                'filter' => array(
                    'lowercase', 
                ),
            )
        ),
        'tokenizer' => array(
            'SQLedgeNGram' => array(
                'type' => 'edgeNGram',
                'min_gram' => 2,
                'max_gram' => 35,
                'side' => 'front'   
            ),
            'standardNoStop' => array(
                'type' => 'standard',
                'stopwords' => ''   
            )   
        )
    )
), true
);

这是我的测试用例字段值:

Abbott and Costello - Funniest Routines, Vol. 

尝试了各种分析器,我似乎无法让它匹配任何包含“和”的东西。

结果:

searching [abbot] 
 @       searchAnalyzer          total results: 1
 @       standard                total results: 1
 @       simple                  total results: 1
 @       whitespace              total results: 1
 @       keyword                 total results: 1


searching [abbot ] 
 @       searchAnalyzer          total results: 1
 @       standard                total results: 1
 @       simple                  total results: 1
 @       whitespace              total results: 1
 @       keyword                 total results: 1


searching [abbot and c] 
     searchAnalyzer          total results: 0
     standard                total results: 0
     simple                  total results: 0
     whitespace              total results: 0
     keyword                 total results: 0


searching [abbot and cost] 
     searchAnalyzer          total results: 0
     standard                total results: 0
     simple                  total results: 0
     whitespace              total results: 0
     keyword                 total results: 0


searching [abbot and costello] 
     searchAnalyzer          total results: 0
     standard                total results: 0
     simple                  total results: 0
     whitespace              total results: 0
     keyword                 total results: 0


searching [abbot costello] 
     searchAnalyzer          total results: 0
     standard                total results: 0
     simple                  total results: 0
     whitespace              total results: 0
     keyword                 total results: 0

【问题讨论】:

    标签: elasticsearch stop-words elastica


    【解决方案1】:

    您的查询中有错字(雅培中缺少第二个 t)。您也不需要通过 ngram 运行搜索。搜索标记器可以是关键字,它仍然适用于短于 35 个字符的短语。顺便说一下,edgeNGram 只会给你尾随通配符。对于前导和尾随通配符,您需要使用 nGram 过滤器。

    【讨论】:

    • 我知道这是一个简单的答案,但感谢您抽出时间指出问题,这让我很伤心.. 检查了所有内容,但最明显的 :(
    猜你喜欢
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 2011-02-11
    • 2013-01-16
    • 2015-09-24
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多