2013-02-14 132 views
0

我似乎无法弄清楚如何获得elasticsearch(通过pyes访问)来搜索复数/单数术语。例如,当我进入Monkies时,我想要得到带有Belt的结果。我看过Elasticsearch not returning singular/plural matches,但似乎无法理解它。下面是一些卷曲陈述Elasticsearch搜索复数

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 

我它得到的地步,寻找皮带给我一些结果...但现在它给了过多的结果。我必须做些什么来让它只返回那个有“带”的条目呢?

回答

2

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

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

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

VS

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

你可以减少一些curl调用,通过这个映射创建你的索引,索引一些数据,并执行一个搜索来显示你不期望的结果?

+0

我编辑的问题,包括卷曲的供词,以及改变了一点东西。它现在正在返回多个结果,但它返回了太多/不相关的结果。谢谢你的帮助。 – 2013-03-01 06:48:35