我正在尝试使用 ElasticSearch 的 RestHighLevelClient API 在 Java 应用程序中使用通配符“*”进行搜索。但没有得到任何匹配。
指数数据:
JEAN
JEAN CHRISTOPHER
JEAN SOMETHING ELSE
使用 URL API 搜索:
http://mylocal-es-server.com/myindex/_search?q=firstName:JEAN*&pretty // 2 hits
JAVA 代码(更新):
public SearchResponse preciseSearch(PreciseSearchRequest req) throws IOException {
// convert my req to org.elasticsearch.action.search.SearchRequest:
SearchRequest searchReq = createSearchRequest(req);
// print searchReq (see below)
return restHighLevelClient.search(searchReq, RequestOptions.DEFAULT); // returns 0 hit
}
打印搜索请求:
{"from":0,"size":1000,"query":{"query":"(firstName:(\"JEAN*\"))","fields:[],"type":"best_fields","default_operator":"or","max_determinzed_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},"sort":[{"age":{"order":"desc"}}]}
索引映射:
"firstName" : { "type": "keyword" }
我怀疑这是由于 type = 关键字而不是文本。但是,为什么使用 URL 搜索可以正常工作呢?
任何指针表示赞赏!我是ES初学者!
谢谢
好的我发现了问题..
有一段代码用双引号包裹了值。双引号本身可以正常工作,但是当有通配符时,它不起作用。
我有:
"query":"(firstName:(\"JEAN*\"))"
它应该是:
"query":"(firstName:(JEAN*))"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句