# Is it possible to do a text query against a (pre)defined set of fields?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-do-a-text-query-against-a-pre-defined-set-of-fields/15141>\
**Category:** Elasticsearch\
**Created:** [January 8, 2014, 11:18am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-text-query-against-a-pre-defined-set-of-fields/15141 "2014-01-08T11:18:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ville\_Mattila](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ville_mattila/32/1457_2.png) [@Ville\_Mattila](https://discuss.elastic.co/u/Ville_Mattila)\
**Post date:** [January 8, 2014, 11:18am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-text-query-against-a-pre-defined-set-of-fields/15141/1 "2014-01-08T11:18:51Z")

</div>

Hi,

I am indexing some large documents in an index. When making full text  
queries, I've generally used {"text": {"\_all": "some text search"}} to find  
all possible results. However, the document contains a few "private" fields  
that should be queryable only by a certain user group.

What I was wondering is if there is a possibility to define some kind of  
alias for a set of fields (or even better - all fields except the set of  
fields) in the mapping definition. I could then do a query {"text":  
{"alias\_for\_public\_fields": "some text search"}} while the private fields  
would not be searched for. I do not know if this is possible already now?

I know that it's possible to list all fields in the query and leave out the  
privates, but as there can be hundreds of fields that should be queryable  
but only 2-3 private fields, listing fields explicitly adds significant  
overhead to the queries.

Best regards,  
Ville

--  
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/8dc6c390-b483-40d0-bc4e-264380743aef%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8dc6c390-b483-40d0-bc4e-264380743aef%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [January 8, 2014, 5:23pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-text-query-against-a-pre-defined-set-of-fields/15141/2 "2014-01-08T17:23:28Z")

</div>

Ville,

Perhaps: Don't include the private fields in \_all. Then a query against  
\_all would be restricted to the (perhaps hundreds) of "public" fields.

A query that includes the private fields would need to list \_all and then  
the private fields. But since you have only 2 or 3 private fields, there  
shouldn't be much overhead on the query.

Brian

--  
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/0692b19c-2c81-441b-ba2c-c7d33f98648c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0692b19c-2c81-441b-ba2c-c7d33f98648c%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ville\_Mattila](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ville_mattila/32/1457_2.png) [@Ville\_Mattila](https://discuss.elastic.co/u/Ville_Mattila)\
**Post date:** [January 8, 2014, 5:56pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-text-query-against-a-pre-defined-set-of-fields/15141/3 "2014-01-08T17:56:41Z")

</div>

Hi,

Well - I think I've understood something wrong here. Isn't \_all a special  
key that includes all indexed fields? Is there possibility to change the  
fields included in \_all?

Ville

Ville,

> Perhaps: Don't include the private fields in \_all. Then a query against  
> \_all would be restricted to the (perhaps hundreds) of "public" fields.
> 
> A query that includes the private fields would need to list \_all and then  
> the private fields. But since you have only 2 or 3 private fields, there  
> shouldn't be much overhead on the query.
> 
> Brian

--  
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/d326a968-9ed9-44e9-8640-9b00d9507c05%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d326a968-9ed9-44e9-8640-9b00d9507c05%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [January 8, 2014, 9:05pm UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-text-query-against-a-pre-defined-set-of-fields/15141/4 "2014-01-08T21:05:23Z")

</div>

Ville,

By default, the \_all field includes all of the indexed field. Then, for  
your private fields, explicitly exclude them from the \_all field by adding  
the following to their properties:

"include\_in\_all" : false

See the ES guide for more details, Specifically, this[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-all-field.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-all-field.html)might help.

I typically disable the \_all field completely to cut down dramatically on  
disk space and build times. But everything else in ES has worked like a  
charm, so I'm sure this would work for you without too much trouble. Good  
luck!

Brian

--  
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/54d7375c-2644-4b81-8e0e-51e74140f0aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/54d7375c-2644-4b81-8e0e-51e74140f0aa%40googlegroups.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, 1:57am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-text-query-against-a-pre-defined-set-of-fields/15141/5 "2017-07-06T01:57:52Z")

</div>

Closed on July 6, 2017, 1:57am UTC


