【问题标题】:Elasticsearch search for pluralsElasticsearch 搜索复数
【发布时间】:2013-03-01 14:47:33
【问题描述】:

我似乎无法弄清楚如何让 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

我已经到了搜索腰带给我一些结果的地步……但现在它给出的结果太多了。我该怎么做才能让它只返回一个包含“腰带”的条目?

【问题讨论】:

    标签: elasticsearch pyes


    【解决方案1】:

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

    顺便说一下,Elasticsearch 可以很容易地比较不同的分析设置。比较:

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

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

    【讨论】:

      【解决方案2】:

      您能否将其简化为几个 curl 调用,这些调用使用此映射创建索引、索引一些数据并执行显示您未预料到的结果的搜索?

      【讨论】:

      • 我已经编辑了问题以包含 curl 语句,并稍微改变了一些内容。它现在返回复数结果,但返回太多/不相关的结果。感谢您的帮助。
      猜你喜欢
      • 1970-01-01
      • 2015-08-02
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多