term 精确查询ElasticSearch

Posted Rover20230226

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了term 精确查询ElasticSearch相关的知识,希望对你有一定的参考价值。

    /**
     * term 精确查询
     */
    @Test
    public void test03() throws IOException 
        SearchRequest searchRequest = new SearchRequest();

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.termQuery("brand","万怡"));
        searchRequest.source(searchSourceBuilder);
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        SearchHits searchHits = searchResponse.getHits();

        System.out.println("总条数:" + searchHits.getTotalHits().value);
        SearchHit[] hits = searchHits.getHits();
        for (SearchHit hit : hits) 
            HotelDoc hotelDoc = JSON.parseObject(hit.getSourceAsString(), HotelDoc.class);
            System.out.println("数据:" + hotelDoc);
        
    

 

以上是关于term 精确查询ElasticSearch的主要内容,如果未能解决你的问题,请参考以下文章

初识ElasticSearch -文档查询之term精确查询

小白学习-ElasticSearch教程 -文档查询之term精确查询

Elasticsearch 结构化搜索、keyword、Term查询

golang_elasticsearch 多精确值匹配

elasticsearch term 查询

Elasticsearch:Terms set 查询