# Java API fieldQuery

**URL:** <https://discuss.elastic.co/t/java-api-fieldquery/10436>\
**Category:** Elasticsearch\
**Created:** [January 21, 2013, 9:50am UTC](https://discuss.elastic.co/t/java-api-fieldquery/10436 "2013-01-21T09:50:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wei\_Hao\_Tan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wei_hao_tan/32/2524_2.png) [@Wei\_Hao\_Tan](https://discuss.elastic.co/u/Wei_Hao_Tan)\
**Post date:** [January 21, 2013, 9:50am UTC](https://discuss.elastic.co/t/java-api-fieldquery/10436/1 "2013-01-21T09:50:03Z")

</div>

Hi, I am currently using the Java API for ES with MongoDB. I use fieldQuery  
for my main search functionality, where I look for a substring within a  
particular field. However, I have one particular document whose value of  
"To To " does not return successfully when I search for it. I had verified  
that it did exist in the index by searching for it via it's ID. Is this  
because "To" is a keyword? Here is the code I am using:

SearchResponse response = client.prepareSearch("mongoindex")

```
    .setSearchType(SearchType.*QUERY_AND_FETCH*)

    .setQuery(*fieldQuery*(field, "\""+value+"\""))

    .setFrom(0).setSize(60).setExplain(*true*)

    .execute()

    .actionGet();

```

--

---

<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:** [January 21, 2013, 10:30am UTC](https://discuss.elastic.co/t/java-api-fieldquery/10436/2 "2013-01-21T10:30:21Z")

</div>

You are using the default analyzer which remove english stop words, such as "a",  
"to"...

That's the reason.

Le 21 janvier 2013 à 10:50, Wei Hao Tan [tanweihao88@gmail.com](mailto:tanweihao88@gmail.com) a écrit :

> Hi, I am currently using the Java API for ES with MongoDB. I use fieldQuery  
> for my main search functionality, where I look for a substring within a  
> particular field. However, I have one particular document whose value of "To  
> To " does not return successfully when I search for it. I had verified that it  
> did exist in the index by searching for it via it's ID. Is this because "To"  
> is a keyword? Here is the code I am using:
> 
> SearchResponse response = client.prepareSearch("mongoindex")
> 
> ```
> .setSearchType(SearchType.QUERY_AND_FETCH)
> 
> .setQuery(fieldQuery(field, "\""+value+"\""))
> 
> .setFrom(0).setSize(60).setExplain(true)
> 
> .execute()
> 
> .actionGet();
> 
> ```
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Wei\_Hao\_Tan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wei_hao_tan/32/2524_2.png) [@Wei\_Hao\_Tan](https://discuss.elastic.co/u/Wei_Hao_Tan)\
**Post date:** [January 21, 2013, 3:23pm UTC](https://discuss.elastic.co/t/java-api-fieldquery/10436/3 "2013-01-21T15:23:46Z")

</div>

Hi David,

I see! Thanks for the help! If that's the case, how do I change the  
analyzer to include the default stop words?

On Monday, January 21, 2013 6:30:21 PM UTC+8, David Pilato wrote:

> You are using the default analyzer which remove english stop words, such  
> as "a", "to"...
> 
> That's the reason.
> 
> Le 21 janvier 2013 à 10:50, Wei Hao Tan \<[tanwe...@gmail.com](mailto:tanwe...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi, I am currently using the Java API for ES with MongoDB. I use  
> fieldQuery for my main search functionality, where I look for a substring  
> within a particular field. However, I have one particular document whose  
> value of "To To " does not return successfully when I search for it. I had  
> verified that it did exist in the index by searching for it via it's ID. Is  
> this because "To" is a keyword? Here is the code I am using:
> 
> SearchResponse response = client.prepareSearch("mongoindex")
> 
> ```
> .setSearchType(SearchType.*QUERY_AND_FETCH*)
> 
> .setQuery(*fieldQuery*(field, "\""+value+"\""))
> 
> .setFrom(0).setSize(60).setExplain(*true*)
> 
> .execute()
> 
> .actionGet();
> 
> ```
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Wei\_Hao\_Tan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wei_hao_tan/32/2524_2.png) [@Wei\_Hao\_Tan](https://discuss.elastic.co/u/Wei_Hao_Tan)\
**Post date:** [January 21, 2013, 4:53pm UTC](https://discuss.elastic.co/t/java-api-fieldquery/10436/4 "2013-01-21T16:53:34Z")

</div>

I managed to figure it out, thanks to these two very informative links!  
[http://elasticsearch-users.115913.n3.nabble.com/I-am-tired-of-continuously-trying-to-override-the-default-analyzer-and-tokanizer-settings-td3350150.html](http://elasticsearch-users.115913.n3.nabble.com/I-am-tired-of-continuously-trying-to-override-the-default-analyzer-and-tokanizer-settings-td3350150.html)

> <https://gist.github.com/1234581>

On Monday, January 21, 2013 11:23:46 PM UTC+8, Wei Hao Tan wrote:

> Hi David,
> 
> I see! Thanks for the help! If that's the case, how do I change the  
> analyzer to include the default stop words?
> 
> On Monday, January 21, 2013 6:30:21 PM UTC+8, David Pilato wrote:
> 
> > You are using the default analyzer which remove english stop words,  
> > such as "a", "to"...
> > 
> > That's the reason.
> > 
> > Le 21 janvier 2013 à 10:50, Wei Hao Tan [tanwe...@gmail.com](mailto:tanwe...@gmail.com) a écrit :
> > 
> > Hi, I am currently using the Java API for ES with MongoDB. I use  
> > fieldQuery for my main search functionality, where I look for a substring  
> > within a particular field. However, I have one particular document whose  
> > value of "To To " does not return successfully when I search for it. I had  
> > verified that it did exist in the index by searching for it via it's ID. Is  
> > this because "To" is a keyword? Here is the code I am using:
> > 
> > SearchResponse response = client.prepareSearch("mongoindex")
> > 
> > ```
> > .setSearchType(SearchType.*QUERY_AND_FETCH*)
> > 
> > .setQuery(*fieldQuery*(field, "\""+value+"\""))
> > 
> > .setFrom(0).setSize(60).setExplain(*true*)
> > 
> > .execute()
> > 
> > .actionGet();
> > 
> > ```
> > 
> > --
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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, 2:55am UTC](https://discuss.elastic.co/t/java-api-fieldquery/10436/5 "2017-07-06T02:55:24Z")

</div>


