# Setting the source on a scan query

**URL:** <https://discuss.elastic.co/t/setting-the-source-on-a-scan-query/4619>\
**Category:** Elasticsearch\
**Created:** [June 14, 2011, 6:45pm UTC](https://discuss.elastic.co/t/setting-the-source-on-a-scan-query/4619 "2011-06-14T18:45:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [June 14, 2011, 6:45pm UTC](https://discuss.elastic.co/t/setting-the-source-on-a-scan-query/4619/1 "2011-06-14T18:45:34Z")

</div>

I have a strange problem which may be user error.

I am trying to perform a scan search using the Java API.

```
SearchResponse _response = getClient().prepareSearch("myindex")
        .setSearchType(SearchType.SCAN)
        .setScroll(SCROLL_TIMEOUT)
        .setSize(BATCH_SIZE / SHARD_COUNT)
        .setSource("{ This is not a valid query, let alone valid JSON}")
        .execute().actionGet();

```

When I execute this operation I don't get any exceptions, although I am  
expecting some type of query parse exception because I am passing in  
gibberish. Instead, the scan results in returning me all records as if I did  
a match\_all search!?

In fact, whenever I do provide a valid search query, I still get the  
match\_all results.

The Curl approach seems to work fine, so perhaps I am using setSource wrong,  
or I need to use some other means of passing my query to the Java API.

Any help?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 15, 2011, 11:12am UTC](https://discuss.elastic.co/t/setting-the-source-on-a-scan-query/4619/2 "2011-06-15T11:12:11Z")

</div>

Here is the javadoc for setSource:

/\*\*

- Sets the source of the request as a json string. Note, settings anything other
- than the search type will cause this source to be overridden, consider using
- {@link #setExtraSource(String)}.  
\*/

Basically, what you do is set the source, and then set the size, which causes the source to be overridden (since it ends up generating its own "source").

On Tuesday, June 14, 2011 at 9:45 PM, James Cook wrote:

> I have a strange problem which may be user error.
> 
> I am trying to perform a scan search using the Java API.
> 
> SearchResponse \_response = getClient().prepareSearch("myindex")  
> .setSearchType(SearchType.SCAN)  
> .setScroll(SCROLL\_TIMEOUT)  
> .setSize(BATCH\_SIZE / SHARD\_COUNT)  
> .setSource("{ This is not a valid query, let alone valid JSON}")  
> .execute().actionGet();
> 
> When I execute this operation I don't get any exceptions, although I am expecting some type of query parse exception because I am passing in gibberish. Instead, the scan results in returning me all records as if I did a match\_all search!?
> 
> In fact, whenever I do provide a valid search query, I still get the match\_all results.
> 
> The Curl approach seems to work fine, so perhaps I am using setSource wrong, or I need to use some other means of passing my query to the Java API.
> 
> Any help?

---

<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, 4:03am UTC](https://discuss.elastic.co/t/setting-the-source-on-a-scan-query/4619/3 "2017-07-06T04:03:31Z")

</div>


