[英]Elastic-search queries in Java: Contains-String query?
I work in Java with Elastic-search and want to filter data by "contains string" parameter. 我在Java中使用Elastic-search,希望通过“包含字符串”参数过滤数据。
For example: retrieve a list of children whose names start with 'r'. 例如:检索名称以“ r”开头的子级列表。
But search query (code below) returns the list of children with names equal (not contains) to 'r'. 但是搜索查询(下面的代码)将返回名称(不包含)为“ r”的子项列表。
I've tried "r*" - no luck. 我尝试过“ r *”-没运气。
builder.must(QueryBuilders.queryStringQuery("r*")
.field("child_name")
.lenient(true)
.escape(true)
.analyzeWildcard(false)
.fuzziness(Fuzziness.ZERO)
.defaultOperator(Operator.AND)
.boost(2.0f));
}
Try another type of QueryBuilder
- WildcardQueryBuilder
: 尝试另一种类型的QueryBuilder
- WildcardQueryBuilder
:
Implements the wildcard search query. 实现通配符搜索查询。 Supported wildcards are *, which matches any character sequence (including the empty one), and ?, which matches any single character. 支持的通配符是*,它匹配任何字符序列(包括空字符),以及?,它匹配任何单个字符。 Note this query can be slow, as it needs to iterate over many terms. 请注意,此查询可能会很慢,因为它需要迭代许多项。 In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards * or ?. 为了防止极慢的WildcardQueries,Wildcard术语不应以通配符*或?之一开头。
Example: 例:
QueryBuilder qb = QueryBuilders.wildcardQuery("user", "k?mc*");
Finally, I found the problem by me-self. 最后,我自己发现了问题。 My problems were two: 我的问题是两个:
.analyzeWildcard(false)
.boost(2.0f))
I change to: 我更改为:
.analyzeWildcard(true)
.boost(1.0f))
And it helped. 它帮助了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.