因此,我可以通过url简化操作
<elastic_host>/indexname/_search?pretty=true&q=text:*str*
我想对RestHighLevelClient做同样的事情,但是不起作用:
SearchRequest searchRequest = new SearchRequest(indexName);
searchRequest.types(INDEX_TYPE);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
QueryBuilder queryBuilder = QueryBuilders.matchQuery(IMAGE_TEXT_FIELD_NAME, "*str*" );
searchSourceBuilder.query(queryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
答案 0 :(得分:0)
等效查询不是匹配查询,而是query_string
查询,因此您可以替换以下行
QueryBuilder queryBuilder = QueryBuilders.matchQuery(IMAGE_TEXT_FIELD_NAME, "*str*" );
这个人
QueryBuilder queryBuilder = QueryBuilders.queryStringQuery("*str*").field(IMAGE_TEXT_FIELD_NAME);