在Elasticsearch中按'id'部分搜索

时间:2018-05-04 08:12:29

标签: elasticsearch

我有json对象,如下所示:

{"id":"one","name":"John"}
{"id":"two","name":"Steve"}

我使用index="people"type="user"id=/document id(one, two)/将它们放入Elasticsearch。     任务是通过id的部分找到这个对象(例如,“ne”或“wo”)。     我正在使用elasticsearch 6.2.4和其他高级客户端

也许有人知道如何以最好的方式进行搜索?

以下是代码示例,我试过了:

  SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); 
    sourceBuilder.query(QueryBuilders.termQuery("id", partOfId)); 
    SearchRequest searchRequest = new SearchRequest(index); 
    searchRequest.types(type); searchRequest.indices("id").source(sourceBuilder);
    SearchResponse searchResponse;
    try (RestHighLevelClient client = getClient()){
     searchResponse = client.search(searchRequest); 
    } catch (IOException e) { 
    throw new IllegalArgumentException(INCORRECT_PARAMS);
 }

0 个答案:

没有答案