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

**URL:** <https://discuss.elastic.co/t/suddenly-my-searchrequestbuilders-setsource-doesnt-work/22402>\
**Category:** Elasticsearch\
**Created:** [February 26, 2015, 5:09am UTC](https://discuss.elastic.co/t/suddenly-my-searchrequestbuilders-setsource-doesnt-work/22402 "2015-02-26T05:09:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonylxc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tonylxc/32/866_2.png) [@tonylxc](https://discuss.elastic.co/u/tonylxc)\
**Post date:** [February 26, 2015, 5:09am UTC](https://discuss.elastic.co/t/suddenly-my-searchrequestbuilders-setsource-doesnt-work/22402/1 "2015-02-26T05:09:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 26, 2015, 5:19am UTC](https://discuss.elastic.co/t/suddenly-my-searchrequestbuilders-setsource-doesnt-work/22402/2 "2015-02-26T05:19:53Z")

</div>

Try remove the "query" level.

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

## HTH

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

> Le 26 févr. 2015 à 06:09, tonylxc [cooniur@gmail.com](mailto: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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/46724ac4-fc6d-4d0f-bb31-7e61baf89439%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/9927DAFC-08DE-49FA-AF42-7A3FD4A0EBD3%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![tonylxc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tonylxc/32/866_2.png) [@tonylxc](https://discuss.elastic.co/u/tonylxc)\
**Post date:** [February 26, 2015, 6:08am UTC](https://discuss.elastic.co/t/suddenly-my-searchrequestbuilders-setsource-doesnt-work/22402/3 "2015-02-26T06:08:43Z")

</div>

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 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 26 févr. 2015 à 06:09, tonylxc \<[coo...@gmail.com](mailto: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](mailto: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)  
> [https://groups.google.com/d/msgid/elasticsearch/46724ac4-fc6d-4d0f-bb31-7e61baf89439%40googlegroups.com?utm\_medium=email&utm\_source=footer](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](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/4d9e5c9b-674f-4b48-848c-1a3c00710fc3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![tonylxc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tonylxc/32/866_2.png) [@tonylxc](https://discuss.elastic.co/u/tonylxc)\
**Post date:** [February 26, 2015, 10:53pm UTC](https://discuss.elastic.co/t/suddenly-my-searchrequestbuilders-setsource-doesnt-work/22402/4 "2015-02-26T22:53:50Z")

</div>

Related issues:

- [Unable to use JSON query string with SearchRequestBuilder (Elasticsearch 1.4.2 & 1.4.4) · Issue #9910 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/9910)
- [ClassNotFoundException: com.vividsolutions.jts.geom.Coordinate · Issue #9891 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/9891)

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:29am UTC](https://discuss.elastic.co/t/suddenly-my-searchrequestbuilders-setsource-doesnt-work/22402/5 "2017-07-06T00:29:45Z")

</div>


