java.lang.IllegalArgumentException: cannot write xcontent for unknown value of type class java.util.UUID?

Hi I am using java high level rest api client to read some documents from an elastic search index and i am getting the following error .

I get this error when i do perform a request on elasticsearch client as below.

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)


Following is the content of my elastic search index .

{"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}}]}}

any idea what am i doing wrong ?

You can't provide a java.util.UUID value. You should provide a string representation of the uuid by invoking its toString() method.

this is my code ,.. where should i change the UUID thing

SearchRequest searchRequest = new SearchRequest();

searchRequest.indicesOptions(IndicesOptions. lenientExpandOpen ());

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

searchSourceBuilder.query(QueryBuilders. matchAllQuery ());

searchRequest.source(searchSourceBuilder);

searchSourceBuilder.from(messageHistoryFilterRequest.getPageNumber());

searchSourceBuilder.size(messageHistoryFilterRequest.getPageSize());

searchSourceBuilder.timeout( new TimeValue(300, TimeUnit. SECONDS ));

BoolQueryBuilder boolQueryBuilder = QueryBuilders. boolQuery ();

RangeQueryBuilder startRangeQueryBuilder = QueryBuilders. rangeQuery ("@timestamp")

.gte(messageHistoryFilterRequest.getStartDate());

boolQueryBuilder.should(startRangeQueryBuilder);

RangeQueryBuilder endRangeQueryBuilder = QueryBuilders. rangeQuery ("@timestamp")

.gte(messageHistoryFilterRequest.getEndDate());

boolQueryBuilder.should(endRangeQueryBuilder);

if (messageHistoryFilterRequest.getMsisdn() != null ) {

WildcardQueryBuilder msisdnWildCardQueryBuilder = new WildcardQueryBuilder("recipient",

messageHistoryFilterRequest.getMsisdn());

boolQueryBuilder.should(msisdnWildCardQueryBuilder);

}

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);

}

if (messageHistoryFilterRequest.getCdrStatus() != null ) {

MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("status",

messageHistoryFilterRequest.getCdrStatus());

boolQueryBuilder.must(matchQueryBuilder);

}

if (messageHistoryFilterRequest.getInventoryCode() != null ) {

MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("inventory",

messageHistoryFilterRequest.getInventoryCode());

boolQueryBuilder.must(matchQueryBuilder);

}

searchSourceBuilder.query(boolQueryBuilder);

SearchResponse searchResponse = null ;

List messageHistories = null ;

According to the stack trace this error occurs in a match query and there are few match queries
in your code. Only for cdr status and inventory code the toString() is not invoked, assuming that inventory code is some sort of an id, I'd guess you need to change:

MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("inventory",

messageHistoryFilterRequest.getInventoryCode());

to

MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("inventory",

messageHistoryFilterRequest.getInventoryCode().toString());

thank you so much ... yes it works

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.