gpt4 book ai didi

java - Elasticsearch 中的 SearchPhaseExecutionException

转载 作者:行者123 更新时间:2023-12-02 03:26:40 25 4
gpt4 key购买 nike

enter image description here

我使用的是Elasticsearch 1.7.5创建索引名称“geo_ip”后,我使用下面的 java 片段代码来搜索名称为 Turkey 的字段 country

 String index = "geo_ip";
String type = "ip";
String field = "country";
String value = "Turkey";
Map<String, String> query = new HashMap<>();
query.put(field, value);
// create client
TransportClient client = EsLoading.settingElasticSearch();
// searching
SearchResponse response = client.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(query)
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();

SearchHit[] result = response.getHits().getHits();
System.out.println("Current result: "+result.length);

但是之后,它出现了这样的问题:

Exception in thread "main" org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query_fetch], all shards failed; shardFailures {[uVH-OgzjQfuUV8Bg_nViHQ][geo_ip][0]: SearchParseException[[geo_ip][0]: from[0],size[60]: Parse Failure [Failed to parse source [{"from":0,"size":60,"query":{"country":"Turkey"},"explain":true}]]]; nested: QueryParsingException[[geo_ip] [_na] query malformed, no field after start_object]; }{[uVH-OgzjQfuUV8Bg_nViHQ][geo_ip][1]: SearchParseException[[geo_ip][1]: from[0],size[60]: Parse Failure [Failed to parse source [{"from":0,"size":60,"query":{"country":"Turkey"},"explain":true}]]]; nested: QueryParsingException[[geo_ip] [_na] query malformed, no field after start_object]; }{[uVH-OgzjQfuUV8Bg_nViHQ][geo_ip][2]: SearchParseException[[geo_ip][2]: from[0],size[60]: Parse Failure [Failed to parse source [{"from":0,"size":60,"query":{"country":"Turkey"},"explain":true}]]]; nested: QueryParsingException[[geo_ip] [_na] query malformed, no field after start_object]; }{[uVH-OgzjQfuUV8Bg_nViHQ][geo_ip][3]: SearchParseException[[geo_ip][3]: from[0],size[60]: Parse Failure [Failed to parse source [{"from":0,"size":60,"query":{"country":"Turkey"},"explain":true}]]]; nested: QueryParsingException[[geo_ip] [_na] query malformed, no field after start_object]; }{[uVH-OgzjQfuUV8Bg_nViHQ][geo_ip][4]: SearchParseException[[geo_ip][4]: from[0],size[60]: Parse Failure [Failed to parse source [{"from":0,"size":60,"query":{"country":"Turkey"},"explain":true}]]]; nested: QueryParsingException[[geo_ip] [_na] query malformed, no field after start_object]; }
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:237)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:183)
at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:565)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

有人可以帮我解决这个问题吗?谢谢。

最佳答案

您的country字段可能已被分析,因此您需要使用小写的turkey进行查询。试试这个:

    SearchResponse response = client.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(QueryBuilders.termQuery("country", "turkey"))
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();

或者使用 match 查询(使用 turkeyTurkey),如下所示:

    SearchResponse response = client.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(QueryBuilders.matchQuery("country", "Turkey"))
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();

关于java - Elasticsearch 中的 SearchPhaseExecutionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38764308/

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