# Filter syntax

**URL:** <https://discuss.elastic.co/t/filter-syntax/12920>\
**Category:** Elasticsearch\
**Created:** [July 24, 2013, 2:38pm UTC](https://discuss.elastic.co/t/filter-syntax/12920 "2013-07-24T14:38:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aYm](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@aYm](https://discuss.elastic.co/u/aYm)\
**Post date:** [July 24, 2013, 2:38pm UTC](https://discuss.elastic.co/t/filter-syntax/12920/1 "2013-07-24T14:38:09Z")

</div>

Hi,

I am new to elasticsearch and I am struggling with a simple syntax.

I created 4 elements like this:  
'{"numvente":1,"numlignvente":1,"produit":2866,"prixunitaire":22.32,"qte":20,"vendeur":"D","numtel":"0653243949","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
'  
'{"numvente":1,"numlignvente":2,"produit":4358,"prixunitaire":3.39,"qte":2,"vendeur":"D","numtel":"0653266649","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
'  
'{"numvente":1,"numlignvente":3,"produit":2538,"prixunitaire":20.253,"qte":1,"vendeur":"D","numtel":"069988203","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
'  
'{"numvente":2,"numlignvente":1,"produit":2230,"prixunitaire":324.99,"qte":3,"vendeur":"D","numtel":"0123456577","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
'

My goal is to be able to search through several elements of my index. In  
this case, I would be able to find any products or phone numbers containing  
the "53" string.

Could you help me correcting this?

{

"query": {  
"filtered": {  
"query": {

```
     "term": "53"
   
 },
 "filter": {
   "match_all": {}
 }

```

}  
}  
}

--  
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:** ![aYm](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@aYm](https://discuss.elastic.co/u/aYm)\
**Post date:** [July 24, 2013, 2:44pm UTC](https://discuss.elastic.co/t/filter-syntax/12920/2 "2013-07-24T14:44:41Z")

</div>

Just one more thing, I set a mapping using nGram tokenizer to be able to  
perform a search inside strings.  
Please find it attached.

Thanks!

Le mercredi 24 juillet 2013 16:38:09 UTC+2, aYm a écrit :

> Hi,
> 
> I am new to elasticsearch and I am struggling with a simple syntax.
> 
> I created 4 elements like this:  
> '{"numvente":1,"numlignvente":1,"produit":2866,"prixunitaire":22.32,"qte":20,"vendeur":"D","numtel":"0653243949","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
> '  
> '{"numvente":1,"numlignvente":2,"produit":4358,"prixunitaire":3.39,"qte":2,"vendeur":"D","numtel":"0653266649","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
> '  
> '{"numvente":1,"numlignvente":3,"produit":2538,"prixunitaire":20.253,"qte":1,"vendeur":"D","numtel":"069988203","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
> '  
> '{"numvente":2,"numlignvente":1,"produit":2230,"prixunitaire":324.99,"qte":3,"vendeur":"D","numtel":"0123456577","rayon":"ELECTRO","magasin":"IDF","region":"1"}  
> '
> 
> My goal is to be able to search through several elements of my index. In  
> this case, I would be able to find any products or phone numbers containing  
> the "53" string.
> 
> Could you help me correcting this?
> 
> {
> 
> "query": {  
> "filtered": {  
> "query": {
> 
> ```
> "term": "53"
>    
> },
> "filter": {
> "match_all": {}
> }
> 
> ```
> 
> }  
> }  
> }

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 24, 2013, 11:09pm UTC](https://discuss.elastic.co/t/filter-syntax/12920/3 "2013-07-24T23:09:52Z")

</div>

Hi,

Your query is off in a few places. First of all, a term query needs both a  
field and value. For example:

{  
"term" : { "numvente" : "53" }  
}

You can also use the \_all field if it is enabled. However, you probably do  
not want the term query, but a query\_string query (or perhaps match):

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

You can omit the field name, and it will default to the \_all field.

Second, your query and filters are reversed. Filters are almost like  
queries, except that the do not contribute to the scoring of a document and  
they can be cached. A standard practice is to execute a match\_all query and  
then filter out documents. Each document will have the same score of 1.0.

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"term": { "\_all": "53" }  
}  
}  
}  
}

Try running some simple queries first before diving into ngrams.

Cheers,

Ivan

On Wed, Jul 24, 2013 at 7:44 AM, aYm [aymeric.martin@ysance.com](mailto:aymeric.martin@ysance.com) wrote:

> Just one more thing, I set a mapping using nGram tokenizer to be able to  
> perform a search inside strings.  
> Please find it attached.
> 
> Thanks!
> 
> Le mercredi 24 juillet 2013 16:38:09 UTC+2, aYm a écrit :
> 
> > Hi,
> > 
> > I am new to elasticsearch and I am struggling with a simple syntax.
> > 
> > I created 4 elements like this:  
> > '{"numvente":1,"numlignvente": **1,"produit":2866,"**  
> > prixunitaire":22.32,"qte":20," **vendeur":"D","numtel":"**  
> > 0653243949","rayon":"ELECTRO",**"magasin":"IDF","region":"1"} '  
> > '{"numvente":1,"numlignvente":2,"produit":4358,"  
> > prixunitaire":3.39,"qte":2,"vendeur":"D","numtel":"  
> > 0653266649","rayon":"ELECTRO",**"magasin":"IDF","region":"1"} '  
> > '{"numvente":1,"numlignvente": **3,"produit":2538,"**  
> > prixunitaire":20.253,"qte":1," **vendeur":"D","numtel":"**  
> > 069988203","rayon":"ELECTRO","**magasin":"IDF","region":"1"} '  
> > '{"numvente":2,"numlignvente":1,"produit":2230,"  
> > prixunitaire":324.99,"qte":3,"vendeur":"D","numtel":"  
> > 0123456577","rayon":"ELECTRO",**"magasin":"IDF","region":"1"} '
> > 
> > My goal is to be able to search through several elements of my index. In  
> > this case, I would be able to find any products or phone numbers containing  
> > the "53" string.
> > 
> > Could you help me correcting this?
> > 
> > {
> > 
> > "query": {  
> > "filtered": {  
> > "query": {
> > 
> > ```
> > "term": "53"
> > 
> > },
> > "filter": {
> > "match_all": {}
> > }
> > 
> > ```
> > 
> > }  
> > }  
> > }
> > 
> > --  
> > 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:** ![aYm](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@aYm](https://discuss.elastic.co/u/aYm)\
**Post date:** [July 26, 2013, 10:31am UTC](https://discuss.elastic.co/t/filter-syntax/12920/4 "2013-07-26T10:31:06Z")

</div>

Thanks Ivan! I'll try this.

Le jeudi 25 juillet 2013 01:09:52 UTC+2, Ivan Brusic a écrit :

> Hi,
> 
> Your query is off in a few places. First of all, a term query needs both a  
> field and value. For example:
> 
> {  
> "term" : { "numvente" : "53" }  
> }
> 
> You can also use the \_all field if it is enabled. However, you probably do  
> not want the term query, but a query\_string query (or perhaps match):  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query/)
> 
> You can omit the field name, and it will default to the \_all field.
> 
> Second, your query and filters are reversed. Filters are almost like  
> queries, except that the do not contribute to the scoring of a document and  
> they can be cached. A standard practice is to execute a match\_all query and  
> then filter out documents. Each document will have the same score of 1.0.
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "term": { "\_all": "53" }  
> }  
> }  
> }  
> }
> 
> Try running some simple queries first before diving into ngrams.
> 
> Cheers,
> 
> Ivan
> 
> On Wed, Jul 24, 2013 at 7:44 AM, aYm \<[aymeric...@ysance.com](mailto:aymeric...@ysance.com) \<javascript:\>\>wrote:
> 
> > Just one more thing, I set a mapping using nGram tokenizer to be able to  
> > perform a search inside strings.  
> > Please find it attached.
> > 
> > Thanks!
> > 
> > Le mercredi 24 juillet 2013 16:38:09 UTC+2, aYm a écrit :
> > 
> > > Hi,
> > > 
> > > I am new to elasticsearch and I am struggling with a simple syntax.
> > > 
> > > I created 4 elements like this:  
> > > '{"numvente":1,"numlignvente": **1,"produit":2866,"**  
> > > prixunitaire":22.32,"qte":20," **vendeur":"D","numtel":"**  
> > > 0653243949","rayon":"ELECTRO",**"magasin":"IDF","region":"1"} '  
> > > '{"numvente":1,"numlignvente":2,"produit":4358,"  
> > > prixunitaire":3.39,"qte":2,"vendeur":"D","numtel":"  
> > > 0653266649","rayon":"ELECTRO",**"magasin":"IDF","region":"1"} '  
> > > '{"numvente":1,"numlignvente": **3,"produit":2538,"**  
> > > prixunitaire":20.253,"qte":1," **vendeur":"D","numtel":"**  
> > > 069988203","rayon":"ELECTRO","**magasin":"IDF","region":"1"} '  
> > > '{"numvente":2,"numlignvente":1,"produit":2230,"  
> > > prixunitaire":324.99,"qte":3,"vendeur":"D","numtel":"  
> > > 0123456577","rayon":"ELECTRO",**"magasin":"IDF","region":"1"} '
> > > 
> > > My goal is to be able to search through several elements of my index. In  
> > > this case, I would be able to find any products or phone numbers containing  
> > > the "53" string.
> > > 
> > > Could you help me correcting this?
> > > 
> > > {
> > > 
> > > "query": {  
> > > "filtered": {  
> > > "query": {
> > > 
> > > ```
> > > "term": "53"
> > >    
> > > },
> > > "filter": {
> > > "match_all": {}
> > > }
> > > 
> > > ```
> > > 
> > > }  
> > > }  
> > > }
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > 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:24am UTC](https://discuss.elastic.co/t/filter-syntax/12920/5 "2017-07-06T02:24:22Z")

</div>


