我是Elasticsearch的新手,正在尝试实现搜索。以下是我的索引和设置curl -XPUT localhost:9200/rets_data/ -d '{ "settings":{ "index":{ "analysis":{ "analyzer":{ "analyzer_startswith":{ "tokenizer":"keyword", "filter":"lowercase" }, "analyzer_whitespacewith":{ "tokenizer":"whitespace", "filter":"lowercase" } } } } }, "mappings":{ "city":{ "properties":{ "CityName":{ "analyzer":"analyzer_startswith", "type":"string" } } }, "rets_aux_subdivision":{ "properties":{ "nn":{ "analyzer":"analyzer_whitespacewith", "type":"string" }, "field_LIST_77":{ "analyzer":"analyzer_whitespacewith", "type":"string" }, "SubDivisionName":{ "analyzer":"analyzer_whitespacewith", "type":"string" }, "SubDivisionAlias":{ "analyzer":"analyzer_whitespacewith", "type":"string" } } }, "rental_aux_subdivision":{ "properties":{ "nn":{ "analyzer":"analyzer_whitespacewith", "type":"string" }, "field_LIST_77":{ "analyzer":"analyzer_whitespacewith", "type":"string" }, "SubDivisionName":{ "analyzer":"analyzer_whitespacewith", "type":"string" }, "SubDivisionAlias":{ "analyzer":"analyzer_whitespacewith", "type":"string" } } } } }'
以下是搜索字符串
curl -XGET localhost:9200/rets_data/rets_aux_subdivision/_search?pretty -d '{"query":{"match_phrase_prefix":{"nn":{"query":"boca w","max_expansions":50}}},"sort":{"total":{"order":"desc"}},"size":100}'
当我搜索“ Boca r”,“ Boca w”之类的任何文本时,都没有得到结果。
我的预期结果如下。
“ Boca w”应该给我以“ Boca w”开头的结果。即“博卡西”,“博卡森林”,“博卡风”
请帮我。
谢谢
您应该使用edgeNgram。在elasticsearch文档中查看。
EdgeNgram过滤器从其中一个准备多个单词,如下所示:
伍兹-> [W,Wo,Woo,Wood,Woods]
它使索引更大,但搜索将比通配符等任何其他选项更有效。这是我在title.ngram上使用ngrams进行的简单索引创建:
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"ngram_analyzer" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : ["lowercase","my_ngram"]
}
},
"filter" : {
"my_ngram" : {
"type" : "edge_ngram",
"min_gram" : 1,
"max_gram" : 50
}
}
}
}
},
"mappings":
{
"post":
{
"properties":
{
"id":
{
"type": "integer",
"index":"no"
},
"title":
{
"type": "text",
"analyzer":"ngram_analyzer"
}
}
}
}
}
并搜索查询:
{
"from" : 0,
"size" : 10,
"query" : {
"match" : {
"title":
{
"query":"press key han",
"operator":"or",
"analyzer":"standard"
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句