gpt4 book ai didi

java - Java中ElasticSearch中的字段搜索?

转载 作者:行者123 更新时间:2023-11-30 02:10:44 25 4
gpt4 key购买 nike

我在elasticsearch中索引了对象:

{"id":"一","name":"约翰"}{"id":"二","name":"史蒂夫"}

我将它们放入弹性索引“people”中,输入“people”和文档“/id(one,two)/”

任务是使用带有其余高级客户端的elasticsearch 6.2.4在java中按“名称”搜索记录。

这是我的代码示例:

SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.termQuery("name", name));
SearchRequest searchRequest = new SearchRequest("people");
searchRequest.types("human");
searchRequest.indices("name").source(sourceBuilder);
SearchResponse searchResponse;
RestHighLevelClient client = getClient();
searchResponse = client.search(searchRequest);

这不起作用。

在执行搜索时需要帮助。

最佳答案

请尝试以下代码。

SearchRequest searchRequest = new SearchRequest("people"); 
searchRequest.types("human");
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.termQuery("name", name"));
searchRequest.source(sourceBuilder);
SearchResponse searchResponse = client.search(searchRequest);

此处name必须为小写。

关于java - Java中ElasticSearch中的字段搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50173722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com