Why is the Java api query slower than the rest call?


(savioteles) #1

When I run the following query, it takes much more time using the JAVA api
than using the REST call (for example using the HEAD ES plugin). Why is
this happening? Can anyone help me?

Thanks!!!

Time:

JAVA api time: 118 ms
REST call: 30 ms

Query:

{
"from": 0,
"size": 0,
"query": {
"query_string": {
"default_operator": "AND",
"query": "new"
}
},
"facets": {
"f": {
"terms": {
"field": "city",
"size": 10
},
"facet_filter": {
"term": {
"state": "NY"
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/bcef4922-e35f-424b-9765-562bb7d837f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(savioteles) #2

I'm using the 1.1.0 ES version.

Em segunda-feira, 19 de maio de 2014 14h28min58s UTC-3, Sávio Salvarino
Teles de Oliveira escreveu:

When I run the following query, it takes much more time using the JAVA api
than using the REST call (for example using the HEAD ES plugin). Why is
this happening? Can anyone help me?

Thanks!!!

Time:

JAVA api time: 118 ms
REST call: 30 ms

Query:

{
"from": 0,
"size": 0,
"query": {
"query_string": {
"default_operator": "AND",
"query": "new"
}
},
"facets": {
"f": {
"terms": {
"field": "city",
"size": 10
},
"facet_filter": {
"term": {
"state": "NY"
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/178270c3-1098-41f7-97cd-4101c176f26a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Ivan Brusic) #3

Can you post the Java code as well? The REST API calls the Java API
underneath, so by definition the REST call should always be slower. There
must be something different in the Java code.

--
Ivan

On Mon, May 19, 2014 at 10:29 AM, Sávio Salvarino Teles de Oliveira <
savio.teles@cuia.com.br> wrote:

I'm using the 1.1.0 ES version.

Em segunda-feira, 19 de maio de 2014 14h28min58s UTC-3, Sávio Salvarino
Teles de Oliveira escreveu:

When I run the following query, it takes much more time using the JAVA
api than using the REST call (for example using the HEAD ES plugin). Why is
this happening? Can anyone help me?

Thanks!!!

Time:

JAVA api time: 118 ms
REST call: 30 ms

Query:

{
"from": 0,
"size": 0,
"query": {
"query_string": {
"default_operator": "AND",
"query": "new"
}
},
"facets": {
"f": {
"terms": {
"field": "city",
"size": 10
},
"facet_filter": {
"term": {
"state": "NY"
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/178270c3-1098-41f7-97cd-4101c176f26a%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/178270c3-1098-41f7-97cd-4101c176f26a%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCRypLMVAZUuMsxkws-EriOu8e3u%2BFWXp0bYJonN9q7LA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(savioteles) #4

Yes, the code is bellow:

String query = ""query": {"query_string": {"default_operator":
"AND","query": "new"}}";

JSONObject jsonObject = new JSONObject(query);
String jsonQuery = jsonObject.get("query").toString();

TermFilterBuilder termFilter = FilterBuilders.termFilter("state", "NY");

FacetBuilder facetBuilder =
FacetBuilders.termsFacet("f").field("city").size(10);

facetBuilder.facetFilter(termFilter);

SearchRequestBuilder request = client.prepareSearch("cities");

request.setQuery(QueryBuilders.wrapperQuery(jsonQuery));

request.addFacet(facetBuilder).setTypes(ATTR).setSearchType(SearchType.DFS_QUERY_AND_FETCH).setFrom(0).setSize(0);

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

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAFKmhPs_J2cERAobLMsKo_FMab%3DpDjECCCmY%3Duw7T%2B%2BLKTtBgg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Ivan Brusic) #5

Why are you creating a JSON object for the query string query? You can
create a query builder object directly. Look at the same Java code on the
Elasticsearch site:

http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html

Instead of the term query, substitute a QueryStringQueryBuilder. Perhaps
the performance degradation is coming from the serializing/deserializing of
the JSON object.

Default search type is QUERY_THEN_FETCH. Using DFS will have some
performance impact, but in my testing it is negligible. Also, are you sure
you want DFS_QUERY*AND*FETCH?

--
Ivan

On Mon, May 19, 2014 at 11:25 AM, Sávio S. Teles de Oliveira <
savio.teles@cuia.com.br> wrote:

Yes, the code is bellow:

String query = ""query": {"query_string": {"default_operator":
"AND","query": "new"}}";

JSONObject jsonObject = new JSONObject(query);
String jsonQuery = jsonObject.get("query").toString();

TermFilterBuilder termFilter = FilterBuilders.termFilter("state", "NY");

FacetBuilder facetBuilder =
FacetBuilders.termsFacet("f").field("city").size(10);

facetBuilder.facetFilter(termFilter);

SearchRequestBuilder request = client.prepareSearch("cities");

request.setQuery(QueryBuilders.wrapperQuery(jsonQuery));

request.addFacet(facetBuilder).setTypes(ATTR).setSearchType(SearchType.DFS_QUERY_AND_FETCH).setFrom(0).setSize(0);

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

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAFKmhPs_J2cERAobLMsKo_FMab%3DpDjECCCmY%3Duw7T%2B%2BLKTtBgg%40mail.gmail.comhttps://groups.google.com/d/msgid/elasticsearch/CAFKmhPs_J2cERAobLMsKo_FMab%3DpDjECCCmY%3Duw7T%2B%2BLKTtBgg%40mail.gmail.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQChYR2YFJEvO_G6LwcoULDfQRNBbuVFF5qnkaEYwAc2jQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(savioteles) #6

Why are you creating a JSON object for the query string query? You can
create a query builder object directly. Look at the same Java code on the
Elasticsearch site:

http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html

Instead of the term query, substitute a QueryStringQueryBuilder. Perhaps
the performance degradation is coming from the serializing/deserializing of
the JSON object.

I have to use the JSON object because the query is dynamic and sent by the
client.

Default search type is QUERY_THEN_FETCH. Using DFS will have some

performance impact, but in my testing it is negligible. Also, are you sure
you want DFS_QUERY*AND*FETCH?

I've changed to QUERY_THEN_FETCH, but didn't work!

I calculated the time when calling the request. Like:

long time = System.currentTimeMillis();
SearchResponse response = request.execute().actionGet();

time = System.currentTimeMillis() - time;

2014-05-19 15:49 GMT-03:00 Ivan Brusic ivan@brusic.com:

Why are you creating a JSON object for the query string query? You can
create a query builder object directly. Look at the same Java code on the
Elasticsearch site:

http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html

Instead of the term query, substitute a QueryStringQueryBuilder. Perhaps
the performance degradation is coming from the serializing/deserializing of
the JSON object.

Default search type is QUERY_THEN_FETCH. Using DFS will have some
performance impact, but in my testing it is negligible. Also, are you sure
you want DFS_QUERY*AND*FETCH?

--
Ivan

On Mon, May 19, 2014 at 11:25 AM, Sávio S. Teles de Oliveira <
savio.teles@cuia.com.br> wrote:

Yes, the code is bellow:

String query = ""query": {"query_string": {"default_operator":
"AND","query": "new"}}";

JSONObject jsonObject = new JSONObject(query);
String jsonQuery = jsonObject.get("query").toString();

TermFilterBuilder termFilter = FilterBuilders.termFilter("state", "NY");

FacetBuilder facetBuilder =
FacetBuilders.termsFacet("f").field("city").size(10);

facetBuilder.facetFilter(termFilter);

SearchRequestBuilder request = client.prepareSearch("cities");

request.setQuery(QueryBuilders.wrapperQuery(jsonQuery));

request.addFacet(facetBuilder).setTypes(ATTR).setSearchType(SearchType.DFS_QUERY_AND_FETCH).setFrom(0).setSize(0);

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

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAFKmhPs_J2cERAobLMsKo_FMab%3DpDjECCCmY%3Duw7T%2B%2BLKTtBgg%40mail.gmail.comhttps://groups.google.com/d/msgid/elasticsearch/CAFKmhPs_J2cERAobLMsKo_FMab%3DpDjECCCmY%3Duw7T%2B%2BLKTtBgg%40mail.gmail.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/h3g3cb2mGJM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQChYR2YFJEvO_G6LwcoULDfQRNBbuVFF5qnkaEYwAc2jQ%40mail.gmail.comhttps://groups.google.com/d/msgid/elasticsearch/CALY%3DcQChYR2YFJEvO_G6LwcoULDfQRNBbuVFF5qnkaEYwAc2jQ%40mail.gmail.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
Atenciosamente,
Sávio S. Teles de Oliveira
voice: +55 62 9136 6996
http://br.linkedin.com/in/savioteles
Mestrando em Ciências da Computação - UFG
Arquiteto de Software
CUIA Internet Brasil

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAFKmhPsUD7YGbq__Y%2B6hPwu8%2By3rC6O%2By9w2vq2fpaFMwOkuYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Sang Dang) #7

Could u try change this:
QueryBuilders.wrapperQuery(jsonQuery ...)
to: QueryBuilders.filteredQuery(...)

Maybe there have some different between filter & query order.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ad71ccd9-c780-491a-b814-6b597e85c2c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(savioteles) #8

I can't use QueryBuilders.*filteredQuery(...) *because the client may sent
a query or a filter or both. Therefore, i have to use
QueryBuilders.wrapperQuery(jsonQuery
...).

2014-05-20 5:31 GMT-03:00 kidkid zkidkid@gmail.com:

Could u try change this:
QueryBuilders.wrapperQuery(jsonQuery ...)
to: QueryBuilders.filteredQuery(...)

Maybe there have some different between filter & query order.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/h3g3cb2mGJM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ad71ccd9-c780-491a-b814-6b597e85c2c6%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/ad71ccd9-c780-491a-b814-6b597e85c2c6%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
Atenciosamente,
Sávio S. Teles de Oliveira
voice: +55 62 9136 6996
http://br.linkedin.com/in/savioteles
Mestrando em Ciências da Computação - UFG
Arquiteto de Software
CUIA Internet Brasil

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAFKmhPtpTDq%2BgEtf4DM9epY3fCvkVUgzp9FVCkos3j4EWAzEBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(savioteles) #9

Any idea?

2014-05-20 7:37 GMT-03:00 Sávio S. Teles de Oliveira <
savio.teles@cuia.com.br>:

I can't use QueryBuilders.*filteredQuery(...) *because the client may
sent a query or a filter or both. Therefore, i have to use QueryBuilders.wrapperQuery(jsonQuery
...).

2014-05-20 5:31 GMT-03:00 kidkid zkidkid@gmail.com:

Could u try change this:

QueryBuilders.wrapperQuery(jsonQuery ...)
to: QueryBuilders.filteredQuery(...)

Maybe there have some different between filter & query order.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/h3g3cb2mGJM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ad71ccd9-c780-491a-b814-6b597e85c2c6%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/ad71ccd9-c780-491a-b814-6b597e85c2c6%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
Atenciosamente,
Sávio S. Teles de Oliveira
voice: +55 62 9136 6996
http://br.linkedin.com/in/savioteles
Mestrando em Ciências da Computação - UFG
Arquiteto de Software
CUIA Internet Brasil

--
Atenciosamente,
Sávio S. Teles de Oliveira
voice: +55 62 9136 6996
http://br.linkedin.com/in/savioteles
Mestrando em Ciências da Computação - UFG
Arquiteto de Software
CUIA Internet Brasil

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAFKmhPv_pdKZAAzuFq8kvi8qr1veXgc5-ZZGH9hiPsH1rkSWBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #10