# Problem with Hebrew search

**URL:** <https://discuss.elastic.co/t/problem-with-hebrew-search/5692>\
**Category:** Elasticsearch\
**Created:** [October 26, 2011, 2:09pm UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692 "2011-10-26T14:09:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlgaT](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@OlgaT](https://discuss.elastic.co/u/OlgaT)\
**Post date:** [October 26, 2011, 2:09pm UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692/1 "2011-10-26T14:09:56Z")

</div>

Hi,

I have problem to find the documents by Hebrew words.  
When I create query I encode the query to UTF-8:

QueryStringQueryBuilder textQueryBuilder = new  
QueryStringQueryBuilder(new String(query.getBytes(),"UTF-8");

It finds the documents that contains the Hebrew word, but also finds  
other documents that contain other engish word.  
For example I search for שלום , but elasticsearch finds also documents  
that contain Olga.

What can be a problem?  
Thank you,  
Olga.

---

<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:** [October 26, 2011, 8:39pm UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692/2 "2011-10-26T20:39:24Z")

</div>

Can you gist a sample code that recreates it? I can try and chase it down.

On Wed, Oct 26, 2011 at 4:09 PM, OlgaT [tubmano@gmail.com](mailto:tubmano@gmail.com) wrote:

> Hi,
> 
> I have problem to find the documents by Hebrew words.  
> When I create query I encode the query to UTF-8:
> 
> QueryStringQueryBuilder textQueryBuilder = new  
> QueryStringQueryBuilder(new String(query.getBytes(),"UTF-8");
> 
> It finds the documents that contains the Hebrew word, but also finds  
> other documents that contain other engish word.  
> For example I search for שלום , but elasticsearch finds also documents  
> that contain Olga.
> 
> What can be a problem?  
> Thank you,  
> Olga.

---

<div class="post-metadata">

**Author:** ![OlgaT](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@OlgaT](https://discuss.elastic.co/u/OlgaT)\
**Post date:** [October 31, 2011, 6:52am UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692/3 "2011-10-31T06:52:27Z")

</div>

It appears that we indexed HTML encoded data - apparently it was a  
problem.However after we removed encoding, we can't find any words in  
Hebrew by Java API, but can find by the following curl command:curl -  
XGET [http://localhost:9200/default/conversation/\_search](http://localhost:9200/default/conversation/_search) -d '{"query" :  
"שלום"}'  
The Java sample code:  
String queryString="שלום"; SearchRequestBuilder searchRequestBuilder =  
client.prepareSearch(tenantName).setTypes(type)  
.setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(queryString);SearchResponse  
response = searchRequestBuilder.execute().actionGet();  
What can be a problem?  
Thanks,Olga  
On Oct 26, 4:09 pm, OlgaT [tubm...@gmail.com](mailto:tubm...@gmail.com) wrote:

> Hi,
> 
> I have problem to find the documents byHebrewwords.  
> When I create query I encode the query to UTF-8:
> 
> QueryStringQueryBuilder textQueryBuilder = new  
> QueryStringQueryBuilder(new String(query.getBytes(),"UTF-8");
> 
> It finds the documents that contains theHebrewword, but also finds  
> other documents that contain other engish word.  
> For example I search for שלום , but elasticsearch finds also documents  
> that contain Olga.
> 
> What can be a problem?  
> Thank you,  
> Olga.

---

<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:** [October 31, 2011, 5:14pm UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692/4 "2011-10-31T17:14:12Z")

</div>

You need to wrap the query string you pass in a QueryBuilders.queryString  
construct. When you pass just a string to the setQuery method, it is  
supposed to be a json. Check the failed shards on the SearchResponse you  
get back, you will see that all are failed with failing to parse the query.

On Mon, Oct 31, 2011 at 8:52 AM, OlgaT [tubmano@gmail.com](mailto:tubmano@gmail.com) wrote:

> It appears that we indexed HTML encoded data - apparently it was a  
> problem.However after we removed encoding, we can't find any words in  
> Hebrew by Java API, but can find by the following curl command:curl -  
> XGET [http://localhost:9200/default/conversation/\_search](http://localhost:9200/default/conversation/_search) -d '{"query" :  
> "שלום"}'  
> The Java sample code:  
> String queryString="שלום"; SearchRequestBuilder searchRequestBuilder =  
> client.prepareSearch(tenantName).setTypes(type)
> 
> .setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(queryString);SearchResponse  
> response = searchRequestBuilder.execute().actionGet();  
> What can be a problem?  
> Thanks,Olga  
> On Oct 26, 4:09 pm, OlgaT [tubm...@gmail.com](mailto:tubm...@gmail.com) wrote:
> 
> > Hi,
> > 
> > I have problem to find the documents byHebrewwords.  
> > When I create query I encode the query to UTF-8:
> > 
> > QueryStringQueryBuilder textQueryBuilder = new  
> > QueryStringQueryBuilder(new String(query.getBytes(),"UTF-8");
> > 
> > It finds the documents that contains theHebrewword, but also finds  
> > other documents that contain other engish word.  
> > For example I search for שלום , but elasticsearch finds also documents  
> > that contain Olga.
> > 
> > What can be a problem?  
> > Thank you,  
> > Olga.

---

<div class="post-metadata">

**Author:** ![OlgaT](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@OlgaT](https://discuss.elastic.co/u/OlgaT)\
**Post date:** [November 1, 2011, 6:57am UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692/5 "2011-11-01T06:57:00Z")

</div>

Oh, of course I use QueryBuilders.queryString(query), but step before.  
Here is the code I use:

QueryStringQueryBuilder textQueryBuilder =  
QueryBuilders.queryString(query);  
searchParams.setQueryString(new  
String(textQueryBuilder.buildAsBytes()));

I think "new String(textQueryBuilder.buildAsBytes())" is the problem.  
I should add "UTF-8" charset to creation String.

Thank you a lot.

On Oct 31, 7:14 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> You need to wrap the query string you pass in a QueryBuilders.queryString  
> construct. When you pass just a string to the setQuery method, it is  
> supposed to be a json. Check the failed shards on the SearchResponse you  
> get back, you will see that all are failed with failing to parse the query.
> 
> On Mon, Oct 31, 2011 at 8:52 AM, OlgaT [tubm...@gmail.com](mailto:tubm...@gmail.com) wrote:
> 
> > It appears that we indexed HTML encoded data - apparently it was a  
> > problem.However after we removed encoding, we can't find any words in  
> > Hebrew by Java API, but can find by the following curl command:curl -  
> > XGEThttp://localhost:9200/default/conversation/\_search-d '{"query" :  
> > "שלום"}'  
> > The Java sample code:  
> > String queryString="שלום"; SearchRequestBuilder searchRequestBuilder =  
> > client.prepareSearch(tenantName).setTypes(type)
> 
> > .setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(queryString);SearchRes ponse  
> > response = searchRequestBuilder.execute().actionGet();  
> > What can be a problem?  
> > Thanks,Olga  
> > On Oct 26, 4:09 pm, OlgaT [tubm...@gmail.com](mailto:tubm...@gmail.com) wrote:
> > 
> > > Hi,
> 
> > > I have problem to find the documents byHebrewwords.  
> > > When I create query I encode the query to UTF-8:
> 
> > > QueryStringQueryBuilder textQueryBuilder = new  
> > > QueryStringQueryBuilder(new String(query.getBytes(),"UTF-8");
> 
> > > It finds the documents that contains theHebrewword, but also finds  
> > > other documents that contain other engish word.  
> > > For example I search for שלום , but elasticsearch finds also documents  
> > > that contain Olga.
> 
> > > What can be a problem?  
> > > Thank you,  
> > > Olga.

---

<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:** [November 1, 2011, 6:14pm UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692/6 "2011-11-01T18:14:44Z")

</div>

You can also just pass a query builder to the SearchRequestBuilder, it will  
work better.

On Tue, Nov 1, 2011 at 8:57 AM, OlgaT [tubmano@gmail.com](mailto:tubmano@gmail.com) wrote:

> Oh, of course I use QueryBuilders.queryString(query), but step before.  
> Here is the code I use:
> 
> QueryStringQueryBuilder textQueryBuilder =  
> QueryBuilders.queryString(query);  
> searchParams.setQueryString(new  
> String(textQueryBuilder.buildAsBytes()));
> 
> I think "new String(textQueryBuilder.buildAsBytes())" is the problem.  
> I should add "UTF-8" charset to creation String.
> 
> Thank you a lot.
> 
> On Oct 31, 7:14 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > You need to wrap the query string you pass in a QueryBuilders.queryString  
> > construct. When you pass just a string to the setQuery method, it is  
> > supposed to be a json. Check the failed shards on the SearchResponse you  
> > get back, you will see that all are failed with failing to parse the  
> > query.
> > 
> > On Mon, Oct 31, 2011 at 8:52 AM, OlgaT [tubm...@gmail.com](mailto:tubm...@gmail.com) wrote:
> > 
> > > It appears that we indexed HTML encoded data - apparently it was a  
> > > problem.However after we removed encoding, we can't find any words in  
> > > Hebrew by Java API, but can find by the following curl command:curl -  
> > > XGEThttp://localhost:9200/default/conversation/\_search-d '{"query" :  
> > > "שלום"}'  
> > > The Java sample code:  
> > > String queryString="שלום"; SearchRequestBuilder searchRequestBuilder =  
> > > client.prepareSearch(tenantName).setTypes(type)
> > 
> > >
> 
> .setSearchType(SearchType.QUERY\_THEN\_FETCH).setQuery(queryString);SearchRes  
> ponse
> 
> > > response = searchRequestBuilder.execute().actionGet();  
> > > What can be a problem?  
> > > Thanks,Olga  
> > > On Oct 26, 4:09 pm, OlgaT [tubm...@gmail.com](mailto:tubm...@gmail.com) wrote:
> > > 
> > > > Hi,
> > 
> > > > I have problem to find the documents byHebrewwords.  
> > > > When I create query I encode the query to UTF-8:
> > 
> > > > QueryStringQueryBuilder textQueryBuilder = new  
> > > > QueryStringQueryBuilder(new String(query.getBytes(),"UTF-8");
> > 
> > > > It finds the documents that contains theHebrewword, but also finds  
> > > > other documents that contain other engish word.  
> > > > For example I search for שלום , but elasticsearch finds also  
> > > > documents  
> > > > that contain Olga.
> > 
> > > > What can be a problem?  
> > > > Thank you,  
> > > > Olga.

---

<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, 3:50am UTC](https://discuss.elastic.co/t/problem-with-hebrew-search/5692/7 "2017-07-06T03:50:13Z")

</div>


