【问题标题】:elasticsearch phrase prefix stops findingelasticsearch 短语前缀停止查找
【发布时间】:2015-07-01 12:37:37
【问题描述】:

我正在使用 elasticsearch 短语前缀查询来进行一些自动完成。 它通常工作得很好,但有时找不到不完整的单词,尽管多一个或少一个字母它确实可以找到它。

例如:通过查询“Anomal”和查询“Anomalie”,它确实找到了包含“Anomalie”的内容,但在“Anomali”中找不到任何内容。这对于用户体验来说真的很奇怪!

我之前的谷歌搜索让我尝试禁用停用词,但这并没有解决我的问题。我尝试在分析器中使用停用词配置并作为过滤器。

复制:

索引创建、配置和添加文档:

curl -XPUT 'http://localhost:9200/elastictests/' -d '{
  "settings" : {
    "index" : {
      "analysis" : {
        "filter" : {
          "french_stemmer" : {
            "type" : "stemmer",
            "name" : "light_french"
          },
          "no_stop" : {
            "type" : "stop",
            "stopwords" : "_none_"
          }
        },
        "analyzer" : {
          "default" : {
            "type" : "custom",
            "stopwords" : "_none_",
            "filter" : [ "standard", "lowercase", "asciifolding", "word_delimiter", "french_stemmer", "no_stop" ],
            "tokenizer" : "standard"
          }
        }
      }
    }
  }
}'

curl -XPUT 'http://localhost:9200/elastictests/test/1' -d '{
    "title": "Anomalie"
}'

这些查询找到了文档:

curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1'  -d '
{
  "query" : {
    "match" : {
        "title" : "Anomalie"
      }
    }
  }
}
'

curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1'  -d '
{
  "query" : {
    "match" : {
      "title" : {
        "query": "Anomalie",
        "type": "phrase_prefix"
      }
    }
  }
}
'

curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1'  -d '
{
  "query" : {
    "match" : {
      "title" : {
        "query": "Anomal",
        "type": "phrase_prefix"
      }
    }
  }
}
'

但是这个没有找到文件,也没有错误:

curl -XGET 'http://localhost:9200/elastictests/_search?pretty=1'  -d '
{
  "query" : {
    "match" : {
      "title" : {
        "query": "Anomali",
        "type": "phrase_prefix"
      }
    }
  }
}
'

知道为什么吗?

【问题讨论】:

    标签: indexing elasticsearch


    【解决方案1】:

    这是因为french_stemmer 源于异常 => 异常

    然而,anomali 不会被归结为 anomal

    异常的索引术语 => 异常

    类似地,当查询词为 Anomalie 时,搜索词被分析为 anomaly 并匹配标题。

    但是,当查询是“Anomali”时,它会被分析为“anomali”,不会发生词干提取。由于索引词是“异常”,因此没有匹配前缀或其他。

    如果您从 OP 中描述的自定义分析器中删除词干分析器,您应该获得此特定用例所需的结果

    例子:

    get elastictests/_analyze?field=title&text=Anomalie
    
    {
       "tokens": [
          {
             "token": "**anomal**",
             "start_offset": 0,
             "end_offset": 8,
             "type": "<ALPHANUM>",
             "position": 1
          }
       ]
    }
    
    get elastictests/_analyze?field=title&text=Anomali
    {
       "tokens": [
          {
             "token": "**anomali**",
             "start_offset": 0,
             "end_offset": 7,
             "type": "<ALPHANUM>",
             "position": 1
          }
       ]
    

    【讨论】:

    • 就是这样!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 2018-04-21
    • 1970-01-01
    • 2012-04-18
    相关资源
    最近更新 更多