# Java API for Elastic Search: Using wildcard to express filters like id\<12\* or a combinations of them

**URL:** <https://discuss.elastic.co/t/java-api-for-elastic-search-using-wildcard-to-express-filters-like-id-12-or-a-combinations-of-them/10562>\
**Category:** Elasticsearch\
**Created:** [January 30, 2013, 9:56pm UTC](https://discuss.elastic.co/t/java-api-for-elastic-search-using-wildcard-to-express-filters-like-id-12-or-a-combinations-of-them/10562 "2013-01-30T21:56:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [January 30, 2013, 9:56pm UTC](https://discuss.elastic.co/t/java-api-for-elastic-search-using-wildcard-to-express-filters-like-id-12-or-a-combinations-of-them/10562/1 "2013-01-30T21:56:45Z")

</div>

Hi,

I've a requirement that talks about implementing a wildcard filter with  
operators like "\<", "\<=","\>","\>=","=","!=".  
Ex: a\<b\* or a\>=del\*

I figured out that for

_#1_ "=", i could create a wilcard query and wrap it in a  
QueryFilterBuilder and append it to other OrFilters or And Filters  
\*  
\*  
_#2_ "!=", i could create a wildcard query, wrap it in a  
QueryFilterBuilder, and then wrap the QueryFilterBuilder in a  
NotFilterBuilder and then append the NotFilterBuilder to other OrFilters or  
And Filters.

If anyone of you have worked on such a requirement, could you pls suggest a  
solution.

In my application, the input is in the form (a\<2&b\>=7\*)|c=test. I create  
one single filter for the query and attach it to the match\_all query.  
Below is one such example  
{  
"from": 0,  
"size": 10,  
"query": {  
"bool": {  
"must": {  
"filtered": {  
"query": {"match\_all": {}},  
"filter": {"term": {"X.id": "\*"}}  
}  
}  
}  
},  
"fields": ["X.id",],"sort": [{"X.id": {"order": "asc"}}]  
}

Thanks,  
John

--  
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:** [January 31, 2013, 3:14am UTC](https://discuss.elastic.co/t/java-api-for-elastic-search-using-wildcard-to-express-filters-like-id-12-or-a-combinations-of-them/10562/2 "2013-01-31T03:14:42Z")

</div>

The first idea that come to my mind is to convert your user entry to Query String syntax: [http://lucene.apache.org/core/4\_1\_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package\_description](http://lucene.apache.org/core/4_1_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description)

Then, pass it to a Match Query or a QueryString query.

But, note that using wildcards will slow your search.

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

Le 30 janv. 2013 à 22:56, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) a écrit :

Hi,

I've a requirement that talks about implementing a wildcard filter with operators like "\<", "\<=","\>","\>=","=","!=".  
Ex: a\<b\* or a\>=del\*

I figured out that for

#1 "=", i could create a wilcard query and wrap it in a QueryFilterBuilder and append it to other OrFilters or And Filters

#2 "!=", i could create a wildcard query, wrap it in a QueryFilterBuilder, and then wrap the QueryFilterBuilder in a NotFilterBuilder and then append the NotFilterBuilder to other OrFilters or And Filters.

If anyone of you have worked on such a requirement, could you pls suggest a solution.

In my application, the input is in the form (a\<2&b\>=7\*)|c=test. I create one single filter for the query and attach it to the match\_all query.  
Below is one such example  
{  
"from": 0,  
"size": 10,  
"query": {  
"bool": {  
"must": {  
"filtered": {  
"query": {"match\_all": {}},  
"filter": {"term": {"X.id": "\*"}}  
}  
}  
}  
},  
"fields": ["X.id",],"sort": [{"X.id": {"order": "asc"}}]  
}

## Thanks, John

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:** ![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:53am UTC](https://discuss.elastic.co/t/java-api-for-elastic-search-using-wildcard-to-express-filters-like-id-12-or-a-combinations-of-them/10562/3 "2017-07-06T02:53:52Z")

</div>


