我希望使用Java API使用弹性搜索来执行此查询。对于模糊查询,如何获取“prefix_length”参数?
查询:
{"query":{"bool":{"should":[
{"fuzzy":{"object.name":{"value":"appl", "max_expansions":"1", "prefix_length" : 3}}},
{"prefix":{"object.name":"appl"}},
{"term":{"object.name":"appl"}}
]}}}
Java API:
QueryBuilder result = QueryBuilders.boolQuery()
.minimumNumberShouldMatch(1)
.should(QueryBuilders.fuzzyQuery(Company.FIELD_NAME, query)) ...
文档here没有解释如何获取“prefix_length”参数。谁能解释一下?谢谢!
答案 0 :(得分:0)
啊哈。可以像这样添加:
should(QueryBuilders.fuzzyQuery(Company.FIELD_NAME, query).maxExpansions(1).prefixLength(query.length() - 1)