# User free text query

**URL:** <https://discuss.elastic.co/t/user-free-text-query/21284>\
**Category:** Elasticsearch\
**Created:** [December 17, 2014, 1:27am UTC](https://discuss.elastic.co/t/user-free-text-query/21284 "2014-12-17T01:27:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 17, 2014, 1:27am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/1 "2014-12-17T01:27:30Z")

</div>

I need to query elasticsearch and let the user specify on which other  
fields to search for certain attributes...

I have a field named "texto" with the actual text on which queries are done.

I have a field name "category" with values like "0001,0003" (meaning the  
record is on categories 1 and 3), or "0001,0005,0007", etc...

If the user enters a search criteria like "computer" it will search on  
field "texto" for the text computer, that works fine.

But I guess there is an option, in which you can specify things like  
"category:0003 computer", this query would need to find records with the  
text "computer" on the field "texto", and additionaly have the value "0003"  
present on the field "category", is this possible?

Bruno

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 17, 2014, 1:54am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/2 "2014-12-17T01:54:28Z")

</div>

Actually, elasticsearch will search computer in \_all field and as you said 0003 in category field.  
You should may be disable \_all field and use the copy\_to feature instead BTW.

If your interface has different inputs for text and category, then you should probably better use the QueryDSL with for example a FilteredQuery, with a matchQuery and a termFilter.

My 2 cents  
David

> Le 17 déc. 2014 à 02:27, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> I need to query elasticsearch and let the user specify on which other fields to search for certain attributes...
> 
> I have a field named "texto" with the actual text on which queries are done.
> 
> I have a field name "category" with values like "0001,0003" (meaning the record is on categories 1 and 3), or "0001,0005,0007", etc...
> 
> If the user enters a search criteria like "computer" it will search on field "texto" for the text computer, that works fine.
> 
> But I guess there is an option, in which you can specify things like "category:0003 computer", this query would need to find records with the text "computer" on the field "texto", and additionaly have the value "0003" present on the field "category", is this possible?
> 
> Bruno
> 
> --  
> 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).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/21A058BD-5BA5-4BCD-9BDA-8D17651A485F%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/21A058BD-5BA5-4BCD-9BDA-8D17651A485F%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 17, 2014, 2:13am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/3 "2014-12-17T02:13:37Z")

</div>

My application interface offers fields for filtering (and they are working  
on elastic), but for power users there is always the free text query  
option, my query in elastic is as follows:

```
   "query" : {
            "filtered" : {
                    "query" : {
                            "match" : {
                                    "texto" : {
                                            "query" : "computer",
                                            "operator" : "and"
                                    }
                            }
                    },
                    "filter" : {
                            "bool" : {
                                    "must" : [
                                            {
                                                    "range" : {
                                                            "datefield" 

```

: {

"gte" : "some date here",

"lte" : "some date here"  
}  
}  
},  
{  
"term" : {  
"filter1" : 1 }  
},  
{  
"term" : {  
"filter2" : 1 }  
},  
{  
"term" : {  
"filter3" : [5] }  
}  
]  
}  
}  
}  
}

That is the structure that I use for every query, the filter values vary  
upon the choices entered by the user, and the "query" itself gets its value  
from a text entry field.

Up to this point everything works fine, but when I put "category:0003  
computer" in the query field, it does not return results, although there  
are results the comply...

On Tuesday, December 16, 2014 8:55:01 PM UTC-5, David Pilato wrote:

> Actually, elasticsearch will search computer in \_all field and as you said  
> 0003 in category field.  
> You should may be disable \_all field and use the copy\_to feature instead  
> BTW.
> 
> If your interface has different inputs for text and category, then you  
> should probably better use the QueryDSL with for example a FilteredQuery,  
> with a matchQuery and a termFilter.
> 
> My 2 cents  
> David
> 
> Le 17 déc. 2014 à 02:27, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> I need to query elasticsearch and let the user specify on which other  
> fields to search for certain attributes...
> 
> I have a field named "texto" with the actual text on which queries are  
> done.
> 
> I have a field name "category" with values like "0001,0003" (meaning the  
> record is on categories 1 and 3), or "0001,0005,0007", etc...
> 
> If the user enters a search criteria like "computer" it will search on  
> field "texto" for the text computer, that works fine.
> 
> But I guess there is an option, in which you can specify things like  
> "category:0003 computer", this query would need to find records with the  
> text "computer" on the field "texto", and additionaly have the value "0003"  
> present on the field "category", is this possible?
> 
> Bruno
> 
> --  
> 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:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 17, 2014, 2:22am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/4 "2014-12-17T02:22:12Z")

</div>

Replace match with a simpleQueryString query.

David

> Le 17 déc. 2014 à 03:13, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> My application interface offers fields for filtering (and they are working on elastic), but for power users there is always the free text query option, my query in elastic is as follows:
> 
> ```
> "query" : {
> "filtered" : {
> "query" : {
> "match" : {
> "texto" : {
> "query" : "computer",
> "operator" : "and"
> }
> }
> },
> "filter" : {
> "bool" : {
> "must" : [
> {
> "range" : {
> "datefield" : {
> "gte" : "some date here",
> "lte" : "some date here"
> }
> }
> },
> {
> "term" : { "filter1" : 1 }
> },
> {
> "term" : { "filter2" : 1 }
> },
> {
> "term" : { "filter3" : [5] }
> }
> ]
> }
> }
> }
> }
> 
> ```
> 
> That is the structure that I use for every query, the filter values vary upon the choices entered by the user, and the "query" itself gets its value from a text entry field.
> 
> Up to this point everything works fine, but when I put "category:0003 computer" in the query field, it does not return results, although there are results the comply...
> 
> > On Tuesday, December 16, 2014 8:55:01 PM UTC-5, David Pilato wrote:  
> > Actually, elasticsearch will search computer in \_all field and as you said 0003 in category field.  
> > You should may be disable \_all field and use the copy\_to feature instead BTW.
> > 
> > If your interface has different inputs for text and category, then you should probably better use the QueryDSL with for example a FilteredQuery, with a matchQuery and a termFilter.
> > 
> > My 2 cents  
> > David
> > 
> > > Le 17 déc. 2014 à 02:27, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > 
> > > I need to query elasticsearch and let the user specify on which other fields to search for certain attributes...
> > > 
> > > I have a field named "texto" with the actual text on which queries are done.
> > > 
> > > I have a field name "category" with values like "0001,0003" (meaning the record is on categories 1 and 3), or "0001,0005,0007", etc...
> > > 
> > > If the user enters a search criteria like "computer" it will search on field "texto" for the text computer, that works fine.
> > > 
> > > But I guess there is an option, in which you can specify things like "category:0003 computer", this query would need to find records with the text "computer" on the field "texto", and additionaly have the value "0003" present on the field "category", is this possible?
> > > 
> > > Bruno
> > > 
> > > --  
> > > 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).  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/38A90388-2728-4C38-83AE-A6A2C39010B3%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/38A90388-2728-4C38-83AE-A6A2C39010B3%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 17, 2014, 2:40am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/5 "2014-12-17T02:40:16Z")

</div>

Ok, it works, but I've found a new problem, it only works if the field  
"category" is exactly "0003", it seems that is not taking in account that  
some records have that field as "0001,0003" or  
"value1,value2,value3,...,0003,0005" and alike...

On Tuesday, December 16, 2014 9:22:22 PM UTC-5, David Pilato wrote:

> Replace match with a simpleQueryString query.
> 
> David
> 
> Le 17 déc. 2014 à 03:13, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> My application interface offers fields for filtering (and they are working  
> on elastic), but for power users there is always the free text query  
> option, my query in elastic is as follows:
> 
> ```
> "query" : {
> "filtered" : {
> "query" : {
> "match" : {
> "texto" : {
> "query" : "computer",
> "operator" : "and"
> }
> }
> },
> "filter" : {
> "bool" : {
> "must" : [
> {
> "range" : {
> 
> ```
> 
> "datefield" : {
> 
> "gte" : "some date here",
> 
> "lte" : "some date here"  
> }  
> }  
> },  
> {  
> "term" : {  
> "filter1" : 1 }  
> },  
> {  
> "term" : {  
> "filter2" : 1 }  
> },  
> {  
> "term" : {  
> "filter3" : [5] }  
> }  
> ]  
> }  
> }  
> }  
> }
> 
> That is the structure that I use for every query, the filter values vary  
> upon the choices entered by the user, and the "query" itself gets its value  
> from a text entry field.
> 
> Up to this point everything works fine, but when I put "category:0003  
> computer" in the query field, it does not return results, although there  
> are results the comply...
> 
> On Tuesday, December 16, 2014 8:55:01 PM UTC-5, David Pilato wrote:
> 
> > Actually, elasticsearch will search computer in \_all field and as you  
> > said 0003 in category field.  
> > You should may be disable \_all field and use the copy\_to feature instead  
> > BTW.
> > 
> > If your interface has different inputs for text and category, then you  
> > should probably better use the QueryDSL with for example a FilteredQuery,  
> > with a matchQuery and a termFilter.
> > 
> > My 2 cents  
> > David
> > 
> > Le 17 déc. 2014 à 02:27, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > 
> > I need to query elasticsearch and let the user specify on which other  
> > fields to search for certain attributes...
> > 
> > I have a field named "texto" with the actual text on which queries are  
> > done.
> > 
> > I have a field name "category" with values like "0001,0003" (meaning the  
> > record is on categories 1 and 3), or "0001,0005,0007", etc...
> > 
> > If the user enters a search criteria like "computer" it will search on  
> > field "texto" for the text computer, that works fine.
> > 
> > But I guess there is an option, in which you can specify things like  
> > "category:0003 computer", this query would need to find records with the  
> > text "computer" on the field "texto", and additionaly have the value "0003"  
> > present on the field "category", is this possible?
> > 
> > Bruno
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 17, 2014, 3:52am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/6 "2014-12-17T03:52:56Z")

</div>

It’s an analysis issue I believe.  
Mostly depends on your mapping for this field.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 17 déc. 2014 à 03:40, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> Ok, it works, but I've found a new problem, it only works if the field "category" is exactly "0003", it seems that is not taking in account that some records have that field as "0001,0003" or "value1,value2,value3,...,0003,0005" and alike...
> 
> On Tuesday, December 16, 2014 9:22:22 PM UTC-5, David Pilato wrote:  
> Replace match with a simpleQueryString query.
> 
> David
> 
> Le 17 déc. 2014 à 03:13, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<javascript:\>\> a écrit :
> 
> > My application interface offers fields for filtering (and they are working on elastic), but for power users there is always the free text query option, my query in elastic is as follows:
> > 
> > ```
> > "query" : {
> > "filtered" : {
> > "query" : {
> > "match" : {
> > "texto" : {
> > "query" : "computer",
> > "operator" : "and"
> > }
> > }
> > },
> > "filter" : {
> > "bool" : {
> > "must" : [
> > {
> > "range" : {
> > "datefield" : {
> > "gte" : "some date here",
> > "lte" : "some date here"
> > }
> > }
> > },
> > {
> > "term" : { "filter1" : 1 }
> > },
> > {
> > "term" : { "filter2" : 1 }
> > },
> > {
> > "term" : { "filter3" : [5] }
> > }
> > ]
> > }
> > }
> > }
> > }
> > 
> > ```
> > 
> > That is the structure that I use for every query, the filter values vary upon the choices entered by the user, and the "query" itself gets its value from a text entry field.
> > 
> > Up to this point everything works fine, but when I put "category:0003 computer" in the query field, it does not return results, although there are results the comply...
> > 
> > On Tuesday, December 16, 2014 8:55:01 PM UTC-5, David Pilato wrote:  
> > Actually, elasticsearch will search computer in \_all field and as you said 0003 in category field.  
> > You should may be disable \_all field and use the copy\_to feature instead BTW.
> > 
> > If your interface has different inputs for text and category, then you should probably better use the QueryDSL with for example a FilteredQuery, with a matchQuery and a termFilter.
> > 
> > My 2 cents  
> > David
> > 
> > Le 17 déc. 2014 à 02:27, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<\>\> a écrit :
> > 
> > > I need to query elasticsearch and let the user specify on which other fields to search for certain attributes...
> > > 
> > > I have a field named "texto" with the actual text on which queries are done.
> > > 
> > > I have a field name "category" with values like "0001,0003" (meaning the record is on categories 1 and 3), or "0001,0005,0007", etc...
> > > 
> > > If the user enters a search criteria like "computer" it will search on field "texto" for the text computer, that works fine.
> > > 
> > > But I guess there is an option, in which you can specify things like "category:0003 computer", this query would need to find records with the text "computer" on the field "texto", and additionaly have the value "0003" present on the field "category", is this possible?
> > > 
> > > Bruno
> > > 
> > > --  
> > > 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) \<\>.  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm_medium=email&utm_source=footer).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm_medium=email&utm_source=footer).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7F4B585C-EA35-4BC8-BFC7-16EC28564A9C%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/7F4B585C-EA35-4BC8-BFC7-16EC28564A9C%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [December 17, 2014, 3:55am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/7 "2014-12-17T03:55:17Z")

</div>

Any pointers on that?

On Tuesday, December 16, 2014 10:53:26 PM UTC-5, David Pilato wrote:

> It’s an analysis issue I believe.  
> Mostly depends on your mapping for this field.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> [http://Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 17 déc. 2014 à 03:40, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Ok, it works, but I've found a new problem, it only works if the field  
> "category" is exactly "0003", it seems that is not taking in account that  
> some records have that field as "0001,0003" or  
> "value1,value2,value3,...,0003,0005" and alike...
> 
> On Tuesday, December 16, 2014 9:22:22 PM UTC-5, David Pilato wrote:
> 
> > Replace match with a simpleQueryString query.
> > 
> > David
> > 
> > Le 17 déc. 2014 à 03:13, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > 
> > My application interface offers fields for filtering (and they are  
> > working on elastic), but for power users there is always the free text  
> > query option, my query in elastic is as follows:
> > 
> > ```
> > "query" : {
> > "filtered" : {
> > "query" : {
> > "match" : {
> > "texto" : {
> > "query" : "computer",
> > "operator" : "and"
> > }
> > }
> > },
> > "filter" : {
> > "bool" : {
> > "must" : [
> > {
> > "range" : {
> > 
> > ```
> > 
> > "datefield" : {
> > 
> > "gte" : "some date here",
> > 
> > "lte" : "some date here"  
> > }  
> > }  
> > },  
> > {  
> > "term" : {  
> > "filter1" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "filter2" : 1 }  
> > },  
> > {  
> > "term" : {  
> > "filter3" : [5] }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }
> > 
> > That is the structure that I use for every query, the filter values vary  
> > upon the choices entered by the user, and the "query" itself gets its value  
> > from a text entry field.
> > 
> > Up to this point everything works fine, but when I put "category:0003  
> > computer" in the query field, it does not return results, although there  
> > are results the comply...
> > 
> > On Tuesday, December 16, 2014 8:55:01 PM UTC-5, David Pilato wrote:
> > 
> > > Actually, elasticsearch will search computer in \_all field and as you  
> > > said 0003 in category field.  
> > > You should may be disable \_all field and use the copy\_to feature instead  
> > > BTW.
> > > 
> > > If your interface has different inputs for text and category, then you  
> > > should probably better use the QueryDSL with for example a FilteredQuery,  
> > > with a matchQuery and a termFilter.
> > > 
> > > My 2 cents  
> > > David
> > > 
> > > Le 17 déc. 2014 à 02:27, Bruno Kamiche [bkam...@gmail.com](mailto:bkam...@gmail.com) a écrit :
> > > 
> > > I need to query elasticsearch and let the user specify on which other  
> > > fields to search for certain attributes...
> > > 
> > > I have a field named "texto" with the actual text on which queries are  
> > > done.
> > > 
> > > I have a field name "category" with values like "0001,0003" (meaning the  
> > > record is on categories 1 and 3), or "0001,0005,0007", etc...
> > > 
> > > If the user enters a search criteria like "computer" it will search on  
> > > field "texto" for the text computer, that works fine.
> > > 
> > > But I guess there is an option, in which you can specify things like  
> > > "category:0003 computer", this query would need to find records with the  
> > > text "computer" on the field "texto", and additionaly have the value "0003"  
> > > present on the field "category", is this possible?
> > > 
> > > Bruno
> > > 
> > > --  
> > > 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).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3dbabf37-f10d-43f0-8c6a-a430c13658d8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3dbabf37-f10d-43f0-8c6a-a430c13658d8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [December 17, 2014, 3:57am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/8 "2014-12-17T03:57:26Z")

</div>

I don’t know if you are aware of analysis process. If not, you could start reading this: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping-analysis.html) [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping-analysis.html](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping-analysis.html)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 17 déc. 2014 à 04:55, Bruno Kamiche [bkamiche@gmail.com](mailto:bkamiche@gmail.com) a écrit :
> 
> Any pointers on that?
> 
> On Tuesday, December 16, 2014 10:53:26 PM UTC-5, David Pilato wrote:  
> It’s an analysis issue I believe.  
> Mostly depends on your mapping for this field.
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com) [http://elasticsearch.com/](http://elasticsearch.com/)  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> > Le 17 déc. 2014 à 03:40, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<javascript:\>\> a écrit :
> > 
> > Ok, it works, but I've found a new problem, it only works if the field "category" is exactly "0003", it seems that is not taking in account that some records have that field as "0001,0003" or "value1,value2,value3,...,0003,0005" and alike...
> > 
> > On Tuesday, December 16, 2014 9:22:22 PM UTC-5, David Pilato wrote:  
> > Replace match with a simpleQueryString query.
> > 
> > David
> > 
> > Le 17 déc. 2014 à 03:13, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<\>\> a écrit :
> > 
> > > My application interface offers fields for filtering (and they are working on elastic), but for power users there is always the free text query option, my query in elastic is as follows:
> > > 
> > > ```
> > > "query" : {
> > > "filtered" : {
> > > "query" : {
> > > "match" : {
> > > "texto" : {
> > > "query" : "computer",
> > > "operator" : "and"
> > > }
> > > }
> > > },
> > > "filter" : {
> > > "bool" : {
> > > "must" : [
> > > {
> > > "range" : {
> > > "datefield" : {
> > > "gte" : "some date here",
> > > "lte" : "some date here"
> > > }
> > > }
> > > },
> > > {
> > > "term" : { "filter1" : 1 }
> > > },
> > > {
> > > "term" : { "filter2" : 1 }
> > > },
> > > {
> > > "term" : { "filter3" : [5] }
> > > }
> > > ]
> > > }
> > > }
> > > }
> > > }
> > > 
> > > ```
> > > 
> > > That is the structure that I use for every query, the filter values vary upon the choices entered by the user, and the "query" itself gets its value from a text entry field.
> > > 
> > > Up to this point everything works fine, but when I put "category:0003 computer" in the query field, it does not return results, although there are results the comply...
> > > 
> > > On Tuesday, December 16, 2014 8:55:01 PM UTC-5, David Pilato wrote:  
> > > Actually, elasticsearch will search computer in \_all field and as you said 0003 in category field.  
> > > You should may be disable \_all field and use the copy\_to feature instead BTW.
> > > 
> > > If your interface has different inputs for text and category, then you should probably better use the QueryDSL with for example a FilteredQuery, with a matchQuery and a termFilter.
> > > 
> > > My 2 cents  
> > > David
> > > 
> > > Le 17 déc. 2014 à 02:27, Bruno Kamiche \<[bkam...@gmail.com](mailto:bkam...@gmail.com) \<\>\> a écrit :
> > > 
> > > > I need to query elasticsearch and let the user specify on which other fields to search for certain attributes...
> > > > 
> > > > I have a field named "texto" with the actual text on which queries are done.
> > > > 
> > > > I have a field name "category" with values like "0001,0003" (meaning the record is on categories 1 and 3), or "0001,0005,0007", etc...
> > > > 
> > > > If the user enters a search criteria like "computer" it will search on field "texto" for the text computer, that works fine.
> > > > 
> > > > But I guess there is an option, in which you can specify things like "category:0003 computer", this query would need to find records with the text "computer" on the field "texto", and additionaly have the value "0003" present on the field "category", is this possible?
> > > > 
> > > > Bruno
> > > > 
> > > > --  
> > > > 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) \<\>.  
> > > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/36882ade-d788-43b7-95fb-96f6d653f934%40googlegroups.com?utm_medium=email&utm_source=footer).  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > 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) \<\>.  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/de59e565-8b10-4cae-8fdb-17aa43591804%40googlegroups.com?utm_medium=email&utm_source=footer).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/03ff907c-e273-48a4-9b82-fc90201cea6d%40googlegroups.com?utm_medium=email&utm_source=footer).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3dbabf37-f10d-43f0-8c6a-a430c13658d8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3dbabf37-f10d-43f0-8c6a-a430c13658d8%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/3dbabf37-f10d-43f0-8c6a-a430c13658d8%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3dbabf37-f10d-43f0-8c6a-a430c13658d8%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5370064F-EF61-46B1-9262-69B54E2FD404%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/5370064F-EF61-46B1-9262-69B54E2FD404%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:43am UTC](https://discuss.elastic.co/t/user-free-text-query/21284/9 "2017-07-06T00:43:20Z")

</div>


