SearchResponse API is not returning Result


(Anusha) #1

Hi Team,

Am using Java API for a query as shown below:

GET dcl_raac_sayt_v2/dcl_raac_sayt_type_v2/_search
{
"size" : 0,
"query" : {
"bool" : {
"must" : [ {
"match" : {
"BrandName.raw" : {
"query" : "dorman",
"type" : "phrase_prefix"
}
}
}, {
"match" : {
"BrandName.raw" : {
"query" : "-",
"type" : "phrase_prefix"
}
}
} ]
}
},
"aggregations" : {
"unique_partsCount" : {
"terms" : {
"field" : "BrandName",
"size" : 0,
"order" : {
"_term" : "asc"
}
},
"aggregations" : {
"parts_count" : {
"cardinality" : {
"field" : "PartNumber",
"precision_threshold" : 40000
}
}
}
},
"unique_values" : {
"terms" : {
"field" : "BrandName",
"size" : 5,
"order" : {
"_term" : "asc"
}
},
"aggregations" : {
"top" : {
"top_hits" : {
"size" : 1
}
}
}
}
}
}

This query when am executing in sense plugin getting response,
but when am using java API for this query am not getting any response.

Here is my Java code Implementation for the above query:

BoolQueryBuilder builder = getSingleFieldBuilder("dorman", "BrandName.raw");

where as the getSingleFieldBuilder() is as below,

private BoolQueryBuilder getSingleFieldBuilder(String saytTerm, String field) {
String term = saytTerm.replaceAll("\*", "");
String terms[] = term.split(" ");
BoolQueryBuilder builder = boolQuery();

    for (int i = 0; i < terms.length; i++) {
        MatchQueryBuilder qs = QueryBuilders.matchPhrasePrefixQuery(field, terms[i]);
        builder.must(qs);
    }
    return builder;
}

The above method will handle the BooleanQueryBuilder and returns builder, that is giving to setQuery(builder) as shown below,

SearchRequestBuilder srb = ESUtility
.getClient()
.prepareSearch()
.setQuery(builder) .addAggregation(terms("unique_partsCount").field("BrandName").size(0).order(Terms.Order.term(true))
.subAggregation(cardinality("parts_count").field("PartNumber").precisionThreshold(40000))) .addAggregation(terms("unique_values").field("BrandName").size(5).order(Terms.Order.term(true)).subAggregation(AggregationBuilders.topHits("top").setSize(1))).setSize(0);

    srb.setIndices(index);
    srb.setTypes(index_type);

SearchResponse response = srb.execute().actionGet();

In response am not getting the hits, don't know the reason, when I debug it, the final srb (SearcjRequestBuilder object) is holding the query that I executed in sense plugin,

But SearchResponse API is not able to execute it, do I need to change any thing in my coding or else any changes required?????

Can anyone help me to sort this issue.....

FYI....
The same API code implementation is working in one of our applications, which is not working here...


(system) #2