NRS
October 3, 2016, 12:56pm
1
I am facing the same issue . When I use curl to get response , it takes around 40-50 ms . But When same query is executed using execute().actionGet() using TransportClient , it takes around 1000 ms. Trying to figure out the root cause and the solution of this problem .
Settings settings = Settings.builder().put("cluster.name", "elasticsearch-stage").build();
productsClient = TransportClient.builder().settings(settings).build()
.addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName(conf.getString("elasticsearch.client")),conf.getInt("elasticsearch.port")));
srb = productsClient.prepareSearch();
srb.setIndices(CustomUtility.readFromConfig("elasticsearch.index.name"));
srb.setTypes(CustomUtility.readFromConfig("elasticsearch.index.type"));
srb.setQuery(orFilterCatId);
srb.setFrom((int) startFrom);
srb.setSize(perPage);
response = srb.execute().actionGet();
Could anybody pls help me out with this.....................
NRS
October 3, 2016, 12:57pm
2
I also tried setExpalin(false)....still no improvement
dadoonet
(David Pilato)
October 3, 2016, 5:26pm
3
Can you describe what you have in orFilterCatId
, perPage
?
May be print with a srb.toString()
what does the request looks like?
Also can you give the exact query you are running with curl
?
NRS
October 4, 2016, 6:16am
4
Thanks for the response .
Following is srb.toString():
{
"from" : 0,
"size" : 60,
"query" : {
"bool" : {
"must" : [ {
"bool" : {
"should" : {
"term" : {
"catid" : "100"
}
}
}
}, {
"term" : {
"winning_variant" : 1
}
}, {
"term" : {
"is_in_stock" : 1
}
}, {
"range" : {
"qty" : {
"from" : 0,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
}, {
"range" : {
"discounted_price" : {
"from" : 0,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
}, {
"range" : {
"price" : {
"from" : 0,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
} ]
}
},
"explain" : false,
"sort" : [ {
"relevance_score" : {
"order" : "desc"
}
}, {
"qty" : {
"order" : "desc"
}
} ]
}
and I give the same query to curl request which looks like
curl -XGET http://localhost:9200/indexname/typename/_search -d' '
And also hit the same query in Sense.
Sense and curl were executed in 40-60 ms and java API query took above 1000ms
dadoonet
(David Pilato)
October 4, 2016, 6:59am
5
Please format your code using </>
icon. It will make your post more readable.
Can you print the output of response.toString()
and the curl full response please?
NRS
October 4, 2016, 7:10am
6
Thanks for the response .
response.toString is as follows
{
"took" : 36,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
}
From above it is clear that it is taking 36 ms but my following lines of code
long startTime = System.currentTimeMillis();
response = srb.execute().actionGet();
long endTime=System.currentTimeMillis();
System.out.println(endTime-startTime);
shows 1752 ms
I am not able to understand this
dadoonet
(David Pilato)
October 4, 2016, 7:11am
7
So the response here is 36ms
. Not 1s
. You have something wrong which is happening in your code AFTER that.
NRS
October 4, 2016, 7:17am
9
Thanks ...will check on this.
jprante
(Jörg Prante)
October 4, 2016, 8:16pm
10
The curl took
time does not take network latency into account.
You should inspect
SearchResponse response = srb.execute().actionGet();
response.getTookInMillis();
and compare it with curl's took
.