QueryBuilders.queryString() does not seems to work properly for me


(noor) #1

Hi,

I had indexed two documents named "tweet" under "default" index. where
each tweet document has a property named "message" which contains two
different paragraphs that I got from some web site. After successfully
adding them to elastic search when try to query then using below code
snippet I do not get any result when I passwas or of in
queryString as my search terms but when I pass in or even is I get
both documents in result. All the search terms that I had mentioned
earlier exists in both documents could anyone please explain what is
the actual problem.

SearchResponse response = client.prepareSearch("default")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.queryString("was"))
.setFrom(0).setSize(60).setExplain(false)
.execute()
.actionGet();


(noor) #2

Even below code is not working :frowning:

SearchResponse response =

client.prepareSearch("default").setTypes("Tweet")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.wildcardQuery("message","was"))
.setFrom(0).setSize(60).setExplain(false)
.execute()
.actionGet();


(Jan Fiedler) #3

I would assume you do not have a mapping setup (relying on default mapping).
This would mean your message is analyzed with the standard analyzer. This
would mean that - by default - English stop words would be removed from your
content. I did not check but would assume that 'was' is considered a stop
word. Please try your query with a term that is not a stopword AND remove
the wildcards (they are not required with a full text search engine).


(system) #4