Hi,
Thanks for replying. I can't use client as the code is building on jenkins server which doesn't have elasticsearch and subsequently the build fails.
My JSON foir searchsourcebuilder
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"match_phrase": {
"dimensions.attributeValue": {
"query": "Order123",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"agg1": {
"terms": {
"field": "dimensions.attributeValue.keyword",
"size": 100,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"aggUpdatedAt": {
"date_histogram": {
"field": "aggUpdatedAt",
"calendar_interval": "1w",
"offset": 0,
"order": {
"_key": "asc"
},
"keyed": false,
"min_doc_count": 1
}
}
}
}
}
}
What i have tried till now
I used my JSON to build searchsourcebuilder from following code
JsonXContentParser xContentParser = new JsonXContentParser(NamedXContentRegistry.EMPTY, null, new JsonFactory().createParser(requestJSON));
SearchSourceBuilder searchsourcebuilder=SearchSourceBuilder.fromXContent(xContentParser);
Where i get this exception => ParsingException[no [query] registered for [bool]]
Similarly for search response I'm writing the code as follows
try {
NamedXContentRegistry registry = new NamedXContentRegistry(getDefaultNamedXContents());
XContentParser parser = JsonXContent.jsonXContent.createParser(registry, null, responseJSON);
return SearchResponse.fromXContent(parser);
} catch (IOException e) {
System.out.println("exception " + e);
}catch (Exception e){
System.out.println("exception " + e);
}
return null;
}
where i get this exception => [ParsedStringTerms] failed to parse field [buckets]