我有个问题。在我的应用程序中,我使用的是 ElasticSearch。我将 JSON 对象发布到我的 ElasticSearch 服务器。该 JSON 对象包含 DSL 查询。所以,我需要做的是查询一些数据的特定索引。
这是查询:
{
"query":{
"indices":{
"indices":[
"index-1"
],
"query":{
"bool":{
"must":[
{
"match":{
"_all":"this is test"
}
}
],
"should":[
{
"match":{
"country":"PL"
}
}
],
"minimum_should_match":1
}
},
"no_match_query":"none"
}
},
"from":0,
"size":10,
"sort":{
"name":{
"order":"ASC"
}
}
}
查询工作得很好,它返回我想要的数据。但是,在 ElasticSearch 日志中,我可以看到:
[2015-05-28 22:08:20,942][DEBUG][action.search.type] [index] [twitter][0], node[X_ASxSKmn-Bzmn-nHLQ8g], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@7b98e9ad] lastShard [true]
org.elasticsearch.search.SearchParseException: [twitter][0]: query[MatchNoDocsQuery],from[0],size[10]: Parse Failure [Failed to parse source [HERE_COMES_MY_JSON]]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:681)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:537)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:509)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:264)
at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
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)
Caused by: org.elasticsearch.search.SearchParseException: [twitter][0]: query[MatchNoDocsQuery],from[0],size[10]: Parse Failure [No mapping found for [name] in order to sort on]
它试图从 twitter 索引中获取一些东西,这是一些用于测试的标准开箱即用索引。为什么?我指定要在 index-1 中搜索,而不是全部搜索。
我找到了解决方法,只是添加:
"ignore_unmapped" : true
排序,但这并不是真正的解决方案。
我不知道这是否重要,但我设置了一个正在调用的 REST,并且在我的 Java 应用程序中,我将 JSON 传递给 ElasticSearch,如下所示:
Client client = new TransportClient(settings);
SearchRequestBuilder builder = client .prepareSearch().setSource(json);
SearchResponse response = builder.execute().actionGet();
任何人都知道有什么问题吗?我真的很感激任何