嗨,我正在使用Java高级rest api客户端从弹性搜索索引中读取一些文档,并且出现以下错误。
当我确实对Elasticsearch客户端执行如下请求时,出现此错误。
elasticSearchClient.search(searchRequest,RequestOptions.DEFAULT);
java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.util.UUID
at org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:833)
at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:804)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:789)
at org.elasticsearch.index.query.MatchQueryBuilder.doXContent(MatchQueryBuilder.java:371)
at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:88)
at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:280)
at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:261)
at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:88)
at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:857)
at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:850)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:842)
at org.elasticsearch.search.builder.SearchSourceBuilder.innerToXContent(SearchSourceBuilder.java:1182)
at org.elasticsearch.search.builder.SearchSourceBuilder.toXContent(SearchSourceBuilder.java:1309)
at org.elasticsearch.common.xcontent.XContentHelper.toXContent(XContentHelper.java:353)
以下是我的弹性搜索索引的内容。
curl -X GET "localhost:9200/mep-report-today/_search/?size=10"
{"took":9,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":100,"max_score":1.0,"hits":[{"_index":"mep-report-today","_type":"doc","_id":"k33fEW0B6qRb3bOs9s4M","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"lH3fEW0B6qRb3bOs9s4M","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"n33fEW0B6qRb3bOs9s4M","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"oH3fEW0B6qRb3bOs9s4M","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"oX3fEW0B6qRb3bOs9s4M","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"on3fEW0B6qRb3bOs9s4N","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"pH3fEW0B6qRb3bOs9s4N","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"rn3fEW0B6qRb3bOs9s4N","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"t33fEW0B6qRb3bOs9s4N","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}},{"_index":"mep-report-today","_type":"doc","_id":"wX3fEW0B6qRb3bOs9s4N","_score":1.0,"_source":{"inventory":"SMS","msg_text":"This is random text","status":"ENROUTE","@timestamp":"2019-09-02T09:48:09.213Z","o_error":"","flight_id":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","recipient":"420736408283","account_id":"a56f7e14-20f9-40e6-90c6-10604140ac5f","sender":"8800111","campaign_id":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","nof_segments":1,"@version":1,"submission_ts":1567681407000,"delivery_ts":1549246209000}}]}}
任何想法导致此错误的原因是什么。 我正在使用弹性搜索Java Rest Client API版本6.6.1
非常感谢您的帮助 谢谢
答案 0 :(得分:0)
我已经使用toString()解决了此问题,messageHistoryFilterRequest.getAccountId()返回的是java.util.UUID。弹性搜索不了解UUID。所以一旦我做一个toString()它就解决了
if (messageHistoryFilterRequest.getAccountId() != null) {
MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("account_id",
messageHistoryFilterRequest.getAccountId().toString());
boolQueryBuilder.must(matchQueryBuilder);
}
if (messageHistoryFilterRequest.getCampaignId() != null) {
MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("campaign_id",
messageHistoryFilterRequest.getCampaignId().toString());
boolQueryBuilder.must(matchQueryBuilder);
}
if (messageHistoryFilterRequest.getFlightId() != null) {
MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("flight_id",
messageHistoryFilterRequest.getFlightId().toString());
boolQueryBuilder.must(matchQueryBuilder);
}