如何忽略IllegalArgumentException:当使用带有elasticsearch 5.5的suggester时,找不到字段的映射
在elasticsearch 2.4中,运行以下查询时我可以获得0次点击,尽管映射中没有my_field:
http://192.168.99.100:9200/myindex/_search
{
"suggest" : {
"my_field-suggestions" : {
"text" : "na",
"completion" : {
"field" : "my_field"
}
}
}
}
结果:
{
"took": 30,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 1,
"failed": 4,
"failures": [
{
"shard": 1,
"index": "myindex",
"node": "PSP1qvhZRwy-FWMqt-p72A",
"reason": {
"type": "exception",
"reason": "Field [my_field] is not a completion suggest field"
}
}
]
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
},
"suggest": {}
}
然而在elasticsearch 5.5.3中,我收到了一个错误:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "no mapping found for field [my_field]"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "myindex",
"node": "Y0UrN9N3RCW7vpWiH0tvtw",
"reason": {
"type": "illegal_argument_exception",
"reason": "no mapping found for field [my_field]"
}
}
]
},
"status": 400
}
在Java程序中,如何处理这个异常?
Failed to execute phase [query], all shards failed; shardFailures {[Y0UrN9N3RCW7vpWiH0tvtw][common_customer][0]: RemoteTransportException[[Y0UrN9N][172.18.0.5:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[no mapping found for field [my_field]]; }{[Y0UrN9N3RCW7vpWiH0tvtw][common_customer][1]: RemoteTransportException[[Y0UrN9N][172.18.0.5:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[no mapping found for field [my_field]]; }{[Y0UrN9N3RCW7vpWiH0tvtw][common_customer][2]: RemoteTransportException[[Y0UrN9N][172.18.0.5:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[no mapping found for field [my_field]]; }{[Y0UrN9N3RCW7vpWiH0tvtw][common_customer][3]: RemoteTransportException[[Y0UrN9N][172.18.0.5:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[no mapping found for field [my_field]]; }{[Y0UrN9N3RCW7vpWiH0tvtw][common_customer][4]: RemoteTransportException[[Y0UrN9N][172.18.0.5:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[no mapping found for field [my_field]]; }
at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:271)
at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:129)
at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:240)
at org.elasticsearch.action.search.InitialSearchPhase.onShardFailure(InitialSearchPhase.java:88)
at org.elasticsearch.action.search.InitialSearchPhase.access$100(InitialSearchPhase.java:47)
at org.elasticsearch.action.search.InitialSearchPhase$1.onFailure(InitialSearchPhase.java:156)
at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51)
at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1067)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1171)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1149)
at org.elasticsearch.transport.TransportService$7.onFailure(TransportService.java:655)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.onFailure(ThreadContext.java:623)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: NotSerializableExceptionWrapper[: no mapping found for field [my_field]]; nested: IllegalArgumentException[no mapping found for field [my_field]];
at org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:618)
at org.elasticsearch.action.search.SearchPhaseExecutionException.guessRootCauses(SearchPhaseExecutionException.java:170)
at org.elasticsearch.action.search.SearchPhaseExecutionException.getCause(SearchPhaseExecutionException.java:111)
at org.elasticsearch.ElasticsearchException.writeTo(ElasticsearchException.java:285)
at org.elasticsearch.action.search.SearchPhaseExecutionException.writeTo(SearchPhaseExecutionException.java:61)
at org.elasticsearch.common.io.stream.StreamOutput.writeException(StreamOutput.java:838)
at org.elasticsearch.ElasticsearchException.writeTo(ElasticsearchException.java:285)
at org.elasticsearch.transport.ActionTransportException.writeTo(ActionTransportException.java:64)
at org.elasticsearch.common.io.stream.StreamOutput.writeException(StreamOutput.java:838)
at org.elasticsearch.transport.TcpTransport.sendErrorResponse(TcpTransport.java:1147)
at org.elasticsearch.transport.TcpTransportChannel.sendResponse(TcpTransportChannel.java:76)
at org.elasticsearch.transport.DelegatingTransportChannel.sendResponse(DelegatingTransportChannel.java:70)
at org.elasticsearch.transport.RequestHandlerRegistry$TransportChannelWrapper.sendResponse(RequestHandlerRegistry.java:123)
at org.elasticsearch.action.support.HandledTransportAction$TransportHandler$1.onFailure(HandledTransportAction.java:77)
at org.elasticsearch.action.search.AbstractSearchAsyncAction.raisePhaseFailure(AbstractSearchAsyncAction.java:219)
... 16 more
Caused by: java.lang.IllegalArgumentException: no mapping found for field [my_field]
at org.elasticsearch.search.suggest.SuggestionBuilder.populateCommonFields(SuggestionBuilder.java:308)
at org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder.build(CompletionSuggestionBuilder.java:358)
at org.elasticsearch.search.suggest.SuggestBuilder.build(SuggestBuilder.java:174)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:660)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:481)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:457)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:253)
at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:330)
at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:327)
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69)
at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:644)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
... 3 more
我在spring boot项目中使用spring-data-elasticsearch。
答案 0 :(得分:0)
在弹性搜索中创建索引时,您必须指定键值对数据。密钥应该是您要搜索的字段名称。请在弹性搜索中输入有关数据的更多信息。
ElasticSearch: http://localhost:9200/ {索引} / _所有/ _mapping /
应该返回以下类型的数据。应该提到NAem领域 {" INDEXNAME" {"映射" {"的typeName" {"属性" {"&#34 ;: {"类型":"文本""字段" {"关键字" {"类型":&# 34;关键字"" ignore_above" 256}}}}}}}}