你好elasticsearch朋友我想在搜索时设置超时。因此,将Settimeout放入SearchRequestBuilder中的10s。但是每次我都会通过查询成为解析失败。我不明白为什么。
这是我的setteMout的搜索controller:
@RestController
public class SearchController {
@Autowired
@Named("es")
private Node node;
@RequestMapping(method = RequestMethod.GET, value = "/search/{query}")
public List<Hit> search(@PathVariable("query") String query){
Client client = node.client();
List<Hit> esData = new ArrayList<Hit>();
SearchRequestBuilder request1 = client.prepareSearch("orange11").setTimeout("10s").setQuery(query);
SearchResponse response1 = request1.execute().actionGet();
System.out.println("Hits: "+response1.getHits());
for(SearchHit hit : response1.getHits()){
Hit hitDto = new Hit(hit.getSource());
Map<String, HighlightField> highlightFields = hit.getHighlightFields();
for(String s : highlightFields.keySet()){
List<String> fragmentsDto = new ArrayList<>();
Text [] fragments = highlightFields.get(s).fragments();
for (Text fragment : fragments){
fragmentsDto.add(fragment.toString());
}
hitDto.addField("_all", fragmentsDto);
}
esData.add(hitDto);
}
return esData;
}
}
这是例外:
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed; shardFailures {[67Vq8cvCSVm9GROgOY-ifQ][orange11][0]: SearchParseException[[orange11][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"timeout":10000,"query_binary":"eyJzaXplIiA6IDEwLCAiZnJvbSIgOiAwLCAicXVlcnkiIDogeyAibWF0Y2giIDogeyAiX2FsbCIgOiB7InF1ZXJ5IiA6ICJkb2xvcmUifX19LCAiaGlnaGxpZ2h0IiA6IHsiZmllbGRzIiA6IHsgIioiIDoge319LCAicmVxdWlyZV9maWVsZF9tYXRjaCIgOiBmYWxzZX19fQ=="}]]]; nested: QueryParsingException[[orange11] [_na] query malformed, no field after start_object]; }{[67Vq8cvCSVm9GROgOY-ifQ][orange11][1]: SearchParseException[[orange11][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"timeout":10000,"query_binary":"eyJzaXplIiA6IDEwLCAiZnJvbSIgOiAwLCAicXVlcnkiIDogeyAibWF0Y2giIDogeyAiX2FsbCIgOiB7InF1ZXJ5IiA6ICJkb2xvcmUifX19LCAiaGlnaGxpZ2h0IiA6IHsiZmllbGRzIiA6IHsgIioiIDoge319LCAicmVxdWlyZV9maWVsZF9tYXRjaCIgOiBmYWxzZX19fQ=="}]]]; nested: QueryParsingException[[orange11] [_na] query malformed, no field after start_object]; }{[67Vq8cvCSVm9GROgOY-ifQ][orange11][2]: SearchParseException[[orange11][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"timeout":10000,"query_binary":"eyJzaXplIiA6IDEwLCAiZnJvbSIgOiAwLCAicXVlcnkiIDogeyAibWF0Y2giIDogeyAiX2FsbCIgOiB7InF1ZXJ5IiA6ICJkb2xvcmUifX19LCAiaGlnaGxpZ2h0IiA6IHsiZmllbGRzIiA6IHsgIioiIDoge319LCAicmVxdWlyZV9maWVsZF9tYXRjaCIgOiBmYWxzZX19fQ=="}]]]; nested: QueryParsingException[[orange11] [_na] query malformed, no field after start_object]; }{[67Vq8cvCSVm9GROgOY-ifQ][orange11][3]: SearchParseException[[orange11][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"timeout":10000,"query_binary":"eyJzaXplIiA6IDEwLCAiZnJvbSIgOiAwLCAicXVlcnkiIDogeyAibWF0Y2giIDogeyAiX2FsbCIgOiB7InF1ZXJ5IiA6ICJkb2xvcmUifX19LCAiaGlnaGxpZ2h0IiA6IHsiZmllbGRzIiA6IHsgIioiIDoge319LCAicmVxdWlyZV9maWVsZF9tYXRjaCIgOiBmYWxzZX19fQ=="}]]]; nested: QueryParsingException[[orange11] [_na] query malformed, no field after start_object]; }{[67Vq8cvCSVm9GROgOY-ifQ][orange11][4]: SearchParseException[[orange11][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"timeout":10000,"query_binary":"eyJzaXplIiA6IDEwLCAiZnJvbSIgOiAwLCAicXVlcnkiIDogeyAibWF0Y2giIDogeyAiX2FsbCIgOiB7InF1ZXJ5IiA6ICJkb2xvcmUifX19LCAiaGlnaGxpZ2h0IiA6IHsiZmllbGRzIiA6IHsgIioiIDoge319LCAicmVxdWlyZV9maWVsZF9tYXRjaCIgOiBmYWxzZX19fQ=="}]]]; nested: QueryParsingException[[orange11] [_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:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
查询是:
{"size" : 10, "from" : 0, "query" : { "match" : { "_all" : {"query" : "'+searchTerm+'"}}}, "highlight" : {"fields" : { "*" : {}}, "require_field_match" : false}}}
节点设置为:
ImmutableSettings.Builder meineSettings = ImmutableSettings.settingsBuilder();
meineSettings.put("node.name", "orange11-node");
meineSettings.put("path.data", "/Users/lucaarchidiacono/IdeaProjects/moap2/MP3_MoapSampleBuild/data/index");
meineSettings.put("index.store.type", "memory");
meineSettings.put("http.enabled", false);
您的解码查询是这个:
{
"size": 10,
"from": 0,
"query": {
"match": {
"_all": {
"query": "dolore"
}
}
},
"highlight": {
"fields": {
"*": {}
},
"require_field_match": false
}
}}
您的结尾有太多的卷发括号,应该是
{
"size": 10,
"from": 0,
"query": {
"match": {
"_all": {
"query": "dolore"
}
}
},
"highlight": {
"fields": {
"*": {}
},
"require_field_match": false
}
} <--- fix this
尝试一下。以毫秒而不是秒数。
GET /_search?timeout=10ms