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