Setting the source on a scan query

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?

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?