# Does filter term/terms support multiple fields/values in java api?

**URL:** <https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010>\
**Category:** Elasticsearch\
**Created:** [July 31, 2013, 5:48am UTC](https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010 "2013-07-31T05:48:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)\
**Post date:** [July 31, 2013, 5:48am UTC](https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010/1 "2013-07-31T05:48:09Z")

</div>

Hi All,

I have the a query that successfully run on rest api as following :

{  
"query": {  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "kimchy"  
}  
},  
"filter" : {  
"term" : { "message" : "trying out", "post\_date" : "2009-11-15T14:12:12"}  
}  
}  
}

}

but how i could replicate that in java code ? I m trying to build the  
filterTerm by

TermFilterBuilder termfilter = FilterBuilders.termFilter("TYPE\_ID", "2");

however i can't find a way to set mutiple fields with terms.

Thanks.

Cyril

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 31, 2013, 6:11am UTC](https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010/2 "2013-07-31T06:11:36Z")

</div>

Hey Cyril,

Are you sure that TermFilter supports multiple terms?  
Never heard about it. Not documented either.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 31 juil. 2013 à 07:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :

Hi All,

I have the a query that successfully run on rest api as following :

{  
"query": {  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "kimchy"  
}  
},  
"filter" : {  
"term" : { "message" : "trying out", "post\_date" : "2009-11-15T14:12:12"}  
}  
}  
}

}

but how i could replicate that in java code ? I m trying to build the filterTerm by

TermFilterBuilder termfilter = FilterBuilders.termFilter("TYPE\_ID", "2");

however i can't find a way to set mutiple fields with terms.

Thanks.

## Cyril

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)\
**Post date:** [July 31, 2013, 6:26am UTC](https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010/3 "2013-07-31T06:26:31Z")

</div>

Hi,

Sry. Further testing on the query with following variation :

1. "term" : { "user" : "kimchy", "post\_date" : "2009-11-15T14:12:12"} -  
Return Result

2. "term" : { "user" : "kimchy1", "post\_date" : "2009-11-15T14:12:12"} -  
Return Result

3)"term" : { "user" : "kimchy", "post\_date" : "2009-11-15T14:12:11"} -  
Return empty

Conclusion : It picks up the last occurrence of field for the term.  
Therefore i guess term does not support multiple fields.

Someone just pass me the query and yup the document doesn't indicate it is  
supported however just wanted to confirm :).

Anyway thanks a lot David.

On Wed, Jul 31, 2013 at 2:11 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Hey Cyril,
> 
> Are you sure that TermFilter supports multiple terms?  
> Never heard about it. Not documented either.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 juil. 2013 à 07:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> Hi All,
> 
> I have the a query that successfully run on rest api as following :
> 
> {  
> "query": {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "query" : "kimchy"  
> }  
> },  
> "filter" : {  
> "term" : { "message" : "trying out", "post\_date" : "2009-11-15T14:12:12"}  
> }  
> }  
> }
> 
> }
> 
> but how i could replicate that in java code ? I m trying to build the  
> filterTerm by
> 
> TermFilterBuilder termfilter = FilterBuilders.termFilter("TYPE\_ID", "2");
> 
> however i can't find a way to set mutiple fields with terms.
> 
> Thanks.
> 
> Cyril
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/jNpeO\_FzZDg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jNpeO_FzZDg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Regards,

Chee Hoo

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 31, 2013, 6:31am UTC](https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010/4 "2013-07-31T06:31:58Z")

</div>

So use a Bool Filter to wrap multiple TermFilter queries in a must clause.  
Or AndFilter.

See [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/java-api/query-dsl-filters/)

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 31 juil. 2013 à 08:26, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :

Hi,

Sry. Further testing on the query with following variation :

1. "term" : { "user" : "kimchy", "post\_date" : "2009-11-15T14:12:12"} - Return Result

2. "term" : { "user" : "kimchy1", "post\_date" : "2009-11-15T14:12:12"} - Return Result

3)"term" : { "user" : "kimchy", "post\_date" : "2009-11-15T14:12:11"} - Return empty

Conclusion : It picks up the last occurrence of field for the term. Therefore i guess term does not support multiple fields.

Someone just pass me the query and yup the document doesn't indicate it is supported however just wanted to confirm :).

Anyway thanks a lot David.

On Wed, Jul 31, 2013 at 2:11 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Hey Cyril,
> 
> Are you sure that TermFilter supports multiple terms?  
> Never heard about it. Not documented either.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 juil. 2013 à 07:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> Hi All,
> 
> I have the a query that successfully run on rest api as following :
> 
> {  
> "query": {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "query" : "kimchy"  
> }  
> },  
> "filter" : {  
> "term" : { "message" : "trying out", "post\_date" : "2009-11-15T14:12:12"}  
> }  
> }  
> }
> 
> }
> 
> but how i could replicate that in java code ? I m trying to build the filterTerm by
> 
> TermFilterBuilder termfilter = FilterBuilders.termFilter("TYPE\_ID", "2");
> 
> however i can't find a way to set mutiple fields with terms.
> 
> Thanks.
> 
> ## Cyril
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/jNpeO\_FzZDg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jNpeO_FzZDg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Regards,

## Chee Hoo

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)\
**Post date:** [July 31, 2013, 6:36am UTC](https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010/5 "2013-07-31T06:36:06Z")

</div>

Cool. Thanks for the link and immediate response.

-Cyril-

On Wed, Jul 31, 2013 at 2:31 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> So use a Bool Filter to wrap multiple TermFilter queries in a must clause.  
> Or AndFilter.
> 
> See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/java-api/query-dsl-filters/)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 juil. 2013 à 08:26, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> Hi,
> 
> Sry. Further testing on the query with following variation :
> 
> 1. "term" : { "user" : "kimchy", "post\_date" : "2009-11-15T14:12:12"} -  
> Return Result
> 
> 2. "term" : { "user" : "kimchy1", "post\_date" : "2009-11-15T14:12:12"} -  
> Return Result
> 
> 3)"term" : { "user" : "kimchy", "post\_date" : "2009-11-15T14:12:11"} -  
> Return empty
> 
> Conclusion : It picks up the last occurrence of field for the term.  
> Therefore i guess term does not support multiple fields.
> 
> Someone just pass me the query and yup the document doesn't indicate it is  
> supported however just wanted to confirm :).
> 
> Anyway thanks a lot David.
> 
> On Wed, Jul 31, 2013 at 2:11 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Hey Cyril,
> > 
> > Are you sure that TermFilter supports multiple terms?  
> > Never heard about it. Not documented either.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 31 juil. 2013 à 07:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> > 
> > Hi All,
> > 
> > I have the a query that successfully run on rest api as following :
> > 
> > {  
> > "query": {  
> > "filtered" : {  
> > "query" : {  
> > "query\_string" : {  
> > "query" : "kimchy"  
> > }  
> > },  
> > "filter" : {  
> > "term" : { "message" : "trying out", "post\_date" : "2009-11-15T14:12:12"}  
> > }  
> > }  
> > }
> > 
> > }
> > 
> > but how i could replicate that in java code ? I m trying to build the  
> > filterTerm by
> > 
> > TermFilterBuilder termfilter = FilterBuilders.termFilter("TYPE\_ID",  
> > "2");
> > 
> > however i can't find a way to set mutiple fields with terms.
> > 
> > Thanks.
> > 
> > Cyril
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/jNpeO\_FzZDg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jNpeO_FzZDg/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Regards,
> 
> Chee Hoo
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/jNpeO\_FzZDg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jNpeO_FzZDg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Regards,

Chee Hoo

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:23am UTC](https://discuss.elastic.co/t/does-filter-term-terms-support-multiple-fields-values-in-java-api/13010/6 "2017-07-06T02:23:37Z")

</div>


