Suddenly, my SearchRequestBuilder's setSource doesn't work!

I'm using the latest Elasticsearch Java API 1.4.4. And I find this issue
annoying me really badly.

Normally, if you want to do a query using JSON string, you could do this:

Client client = ...

String query =
"{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setSource(query);

logger.debug(request.toString());

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

And then parse the response.

But it doesn't work for me. The response I expected is get some data with
_id=100, but the response I get is all the data. And the debug output
prints "{ }".

To be precisely, it worked yesterday with version 1.4.2, but not today. And
even I downgraded to 1.4.2, it doesn't work!!

But if I use the QueryBuilders to do the same query, it works. And the
debug output prints the equivalent JSON query string.

Client client = ...

String query =
"{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.termFilter("_id", "100")));

logger.debug(request.toString());

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

Does anyone know why it happens?

--
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/46724ac4-fc6d-4d0f-bb31-7e61baf89439%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Try remove the "query" level.

String query = "{"filtered":{"filter":{"term":{"_id":"100"}}}}";

HTH

David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 26 févr. 2015 à 06:09, tonylxc cooniur@gmail.com a écrit :

I'm using the latest Elasticsearch Java API 1.4.4. And I find this issue annoying me really badly.

Normally, if you want to do a query using JSON string, you could do this:

Client client = ...

String query = "{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setSource(query);

logger.debug(request.toString());

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

And then parse the response.

But it doesn't work for me. The response I expected is get some data with _id=100, but the response I get is all the data. And the debug output prints "{ }".

To be precisely, it worked yesterday with version 1.4.2, but not today. And even I downgraded to 1.4.2, it doesn't work!!

But if I use the QueryBuilders to do the same query, it works. And the debug output prints the equivalent JSON query string.

Client client = ...

String query = "{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter("_id", "100")));

logger.debug(request.toString());

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

Does anyone know why it happens?

--
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/46724ac4-fc6d-4d0f-bb31-7e61baf89439%40googlegroups.com.
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/9927DAFC-08DE-49FA-AF42-7A3FD4A0EBD3%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

Yeah, I did what you said and it works.

However, my query is more complex than the example I posted.

The real query is something like this. It has been working very well, (i.e.
through setSource() method), since my previous commit about 3 months ago.
But it just stopped working today.

Does Elasticsearch change something in the latest version?

{
"size": "100",
"query": {
"indices": {
"no_match_query": "none",
"indices": [
"some_index"
],
"query": {
"nested": {
"path": "NE",
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"NE.CODE": "CODE_1"
}
},
{
"script": {
"script": "str = doc[fieldName].value; if (str ==
null) return false; else return str.toInteger() < fieldValue;",
"params": {
"fieldName": "NE.VALUE",
"fieldValue": 90
}
}
},
{
"range": {
"NE.DAYS": {
"from": 98,
"to": 104
}
}
}
]
}
}
}
}
}
}
}
},
"post_filter": {
"query": {
"nested": {
"path": "NE",
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"NE.": "CODE_2"
}
},
{
"range": {
"NE.VALUE": {
"from": 70,
"to": 104
}
}
},
{
"term": {
"NE.LOCATION": "SOME_LOCATION"
}
}
]
}
}
}
}
}
}
}
}

On Wednesday, February 25, 2015 at 9:20:31 PM UTC-8, David Pilato wrote:

Try remove the "query" level.

String query = "{"filtered":{"filter":{"term":{"_id":"100"}}}}";

HTH

David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 26 févr. 2015 à 06:09, tonylxc <coo...@gmail.com <javascript:>> a
écrit :

I'm using the latest Elasticsearch Java API 1.4.4. And I find this issue
annoying me really badly.

Normally, if you want to do a query using JSON string, you could do this:

Client client = ...

String query =
"{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setSource(query);

logger.debug(request.toString());

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

And then parse the response.

But it doesn't work for me. The response I expected is get some data with
_id=100, but the response I get is all the data. And the debug output
prints "{ }".

To be precisely, it worked yesterday with version 1.4.2, but not today.
And even I downgraded to 1.4.2, it doesn't work!!

But if I use the QueryBuilders to do the same query, it works. And the
debug output prints the equivalent JSON query string.

Client client = ...

String query =
"{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.termFilter("_id", "100")));

logger.debug(request.toString());

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

Does anyone know why it happens?

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/46724ac4-fc6d-4d0f-bb31-7e61baf89439%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/46724ac4-fc6d-4d0f-bb31-7e61baf89439%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/4d9e5c9b-674f-4b48-848c-1a3c00710fc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Related issues:

On Wednesday, February 25, 2015 at 9:09:15 PM UTC-8, tonylxc wrote:

I'm using the latest Elasticsearch Java API 1.4.4. And I find this issue
annoying me really badly.

Normally, if you want to do a query using JSON string, you could do this:

Client client = ...

String query =
"{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setSource(query);

logger.debug(request.toString());

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

And then parse the response.

But it doesn't work for me. The response I expected is get some data with
_id=100, but the response I get is all the data. And the debug output
prints "{ }".

To be precisely, it worked yesterday with version 1.4.2, but not today.
And even I downgraded to 1.4.2, it doesn't work!!

But if I use the QueryBuilders to do the same query, it works. And the
debug output prints the equivalent JSON query string.

Client client = ...

String query =
"{"query":{"filtered":{"filter":{"term":{"_id":"100"}}}}}";

SearchRequestBuilder request = client
.prepareSearch("patient_centric_1")
.setTypes("patient_data")
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.termFilter("_id", "100")));

logger.debug(request.toString());

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

Does anyone know why it happens?

--
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/0fe4342b-6422-4277-875c-aa9579ff38c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.