elasticsearch - Elasticsearch搜索复数

标签 elasticsearch pyes

我似乎无法弄清楚如何让elasticsearch(通过pyes访问)来搜索复数/单数术语。例如,当我输入Monkies时,我想获得包含Belt的结果。我看过Elasticsearch not returning singular/plural matches,但似乎无法理解。这是一些curl声明

curl -XDELETE localhost:9200/myindex

curl -XPOST localhost:9200/myindex -d '
{"index": 
  { "number_of_shards": 1,
    "analysis": {
       "filter": {
                "myfilter": {
                    "type" : "porter_stem",
                    "language" : "English"
                }
                 },
       "analyzer": {
             "default" : {                    
                 "tokenizer" : "nGram",
                 "filter" : ["lowercase", "myfilter"]
              },
             "index_analyzer" : {                    
                 "tokenizer" : "nGram",
                 "filter" : ["lowercase", "myfilter"]
              },
              "search_analyzer" : {                                                    
                  "tokenizer" : "nGram",
                  "filter" : ["lowercase", "myfilter"]
              }
        }
     }
  }
}
}'

curl -XPUT localhost:9200/myindex/mytype/_mapping -d '{
    "tweet" : {
        "date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy"],
        "properties" : {
            "user": {"type":"string"},
            "post_date": {"type": "date"},
            "message" : {"type" : "string", "analyzer": "search_analyzer"}
        }
    }}'

curl -XPUT 'http://localhost:9200/myindex/mytype/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "belt knife is a cool thing"
}'

curl -XPUT 'http://localhost:9200/myindex/mytype/2' -d '{
"user" : "alwild",
"post_date" : "2009-11-15T14:12:12",
"message" : "second message with nothing else"
}'

curl -XGET localhost:9200/myindex/mytype/_search?q=message:belts

我发现搜索皮带给我一些结果...但是现在它给出了太多结果。我该怎么做才能使其仅返回其中带有“皮带”的条目?

最佳答案

默认情况下,查询是针对使用标准分析器的_all字段执行的,因此没有词干。尝试使用诸如name:Monkies之类的查询进行搜索。出于生产目的,请使用match查询,该查询将在查询和字段映射之间正确连接分析器。

顺便说一下,Elasticsearch使比较不同的分析设置变得非常容易。相比:

http://localhost:9200/_analyze?text=Monkies&analyzer=standard


http://localhost:9200/_analyze?text=Monkies&analyzer=snowball

关于elasticsearch - Elasticsearch搜索复数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14868691/

相关文章:

java - 将纪元以来的毫秒数转换为 1582 年之前的日历日期时出现问题

python - Elasticsearch : pyes. 异常。IndexMissing Exception 搜索结果异常

search - 弹性启动时BindTransportException

python - 如何使用TermQuery对多个term进行AND查询?

python - 将 "facet_filter"查询转换为 pyes 格式

elasticsearch - 重命名elasticsearch响应中的字段

elasticsearch - 如何在 Elasticsearch 中查询自动完成

elasticsearch - 使用 Elasticsearch 进行过滤查询

go - 我可以将Elasticsearch与需要身份验证的数据一起使用吗(例如仅登录用户)

elasticsearch - 如何存储所有属性的原始值?