# Possible to have something like \_all with own name for specific fields?

**URL:** <https://discuss.elastic.co/t/possible-to-have-something-like--all-with-own-name-for-specific-fields/10226>\
**Category:** Elasticsearch\
**Created:** [January 4, 2013, 8:57am UTC](https://discuss.elastic.co/t/possible-to-have-something-like--all-with-own-name-for-specific-fields/10226 "2013-01-04T08:57:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan\_Seidt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephan_seidt/32/2336_2.png) [@Stephan\_Seidt](https://discuss.elastic.co/u/Stephan_Seidt)\
**Post date:** [January 4, 2013, 8:57am UTC](https://discuss.elastic.co/t/possible-to-have-something-like--all-with-own-name-for-specific-fields/10226/1 "2013-01-04T08:57:18Z")

</div>

Hi,

is it possible to have a field similar to \_all but with its own name and  
only for specific fields of the source document?

As an example, two docs of the same type with two fields "linkA" and  
"linkB" which should be mapped to \_links:

Doc 1: {"linkA": "[http://0000.com](http://0000.com)", "linkB": "[http://0001.com](http://0001.com)"}  
Doc 2: {"linkA": "[http://0010.com](http://0010.com)", "linkB": "[http://0011.us](http://0011.us)"}

Now I don't want linkA and linkB to be included in \_all but, let's say, in  
\_links so I can search for any link like this:

{"filter": {"term": {"\_links": "[http://0010.com](http://0010.com)"}}} -\> Doc 2

Is this perhaps possible by using multi\_field and mapping to an identical  
\_links name for linkA and linkB?

Cheers  
Stephan

--

---

<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:** [January 4, 2013, 5:29pm UTC](https://discuss.elastic.co/t/possible-to-have-something-like--all-with-own-name-for-specific-fields/10226/2 "2013-01-04T17:29:00Z")

</div>

I usually handle this behavior on the indexing side, outside of  
Elasticsearch. Related fields use the same field name.

Do you need the \_all field in general? If you don't, you can  
set include\_in\_all to false for every field except the link fields. If not,  
there is an index\_name setting in the mapping that I have never used. From  
the description, it sounds like it should support what you are looking for.  
Multi-field would not work since they are based off of the original field.

> **[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.

--  
Ivan

On Fri, Jan 4, 2013 at 12:57 AM, Stephan Seidt [evilhackerdude@gmail.com](mailto:evilhackerdude@gmail.com)wrote:

> Hi,
> 
> is it possible to have a field similar to \_all but with its own name and  
> only for specific fields of the source document?
> 
> As an example, two docs of the same type with two fields "linkA" and  
> "linkB" which should be mapped to \_links:
> 
> Doc 1: {"linkA": "[http://0000.com](http://0000.com)", "linkB": "[http://0001.com](http://0001.com)"}  
> Doc 2: {"linkA": "[http://0010.com](http://0010.com)", "linkB": "[http://0011.us](http://0011.us)"}
> 
> Now I don't want linkA and linkB to be included in \_all but, let's say, in  
> \_links so I can search for any link like this:
> 
> {"filter": {"term": {"\_links": "[http://0010.com](http://0010.com)"}}} -\> Doc 2
> 
> Is this perhaps possible by using multi\_field and mapping to an identical  
> \_links name for linkA and linkB?
> 
> Cheers  
> Stephan
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 7, 2013, 1:30am UTC](https://discuss.elastic.co/t/possible-to-have-something-like--all-with-own-name-for-specific-fields/10226/3 "2013-01-07T01:30:13Z")

</div>

Besides using the \_all field and index\_name attribute as Ivan suggested,  
you can also use mutli\_match query to search multiple fields at the same  
time:

```
    "multi_match": {
        "query" : "your query goes here",
        "fields" : ["link*"]        
    }

```

or use mutli\_field with "path": "just\_name" attribute to copy content of  
several fields into a single  
field: [Сopy multiple fields into a single field in ElasticSearch · GitHub](https://gist.github.com/6a96abda46d94847657d)

On Friday, January 4, 2013 12:29:00 PM UTC-5, Ivan Brusic wrote:

> I usually handle this behavior on the indexing side, outside of  
> Elasticsearch. Related fields use the same field name.
> 
> Do you need the \_all field in general? If you don't, you can  
> set include\_in\_all to false for every field except the link fields. If not,  
> there is an index\_name setting in the mapping that I have never used. From  
> the description, it sounds like it should support what you are looking for.  
> Multi-field would not work since they are based off of the original field.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/core-types.html)
> 
> --  
> Ivan
> 
> On Fri, Jan 4, 2013 at 12:57 AM, Stephan Seidt \<[evilhac...@gmail.com](mailto:evilhac...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > is it possible to have a field similar to \_all but with its own name and  
> > only for specific fields of the source document?
> > 
> > As an example, two docs of the same type with two fields "linkA" and  
> > "linkB" which should be mapped to \_links:
> > 
> > Doc 1: {"linkA": "[http://0000.com](http://0000.com)", "linkB": "[http://0001.com](http://0001.com)"}  
> > Doc 2: {"linkA": "[http://0010.com](http://0010.com)", "linkB": "[http://0011.us](http://0011.us)"}
> > 
> > Now I don't want linkA and linkB to be included in \_all but, let's say,  
> > in \_links so I can search for any link like this:
> > 
> > {"filter": {"term": {"\_links": "[http://0010.com](http://0010.com)"}}} -\> Doc 2
> > 
> > Is this perhaps possible by using multi\_field and mapping to an identical  
> > \_links name for linkA and linkB?
> > 
> > Cheers  
> > Stephan
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Stephan\_Seidt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephan_seidt/32/2336_2.png) [@Stephan\_Seidt](https://discuss.elastic.co/u/Stephan_Seidt)\
**Post date:** [January 7, 2013, 8:39am UTC](https://discuss.elastic.co/t/possible-to-have-something-like--all-with-own-name-for-specific-fields/10226/4 "2013-01-07T08:39:44Z")

</div>

Using multi\_field to copy relevant fields into a single field is what's  
best I think.

With multi\_match or a boolean query there'd be a problem: All possible  
fields are not easily known at query time and the list can be large.

For that reason I'll choose the optimization of having a single compound  
field at indexing time.

Thank you both for your help!  
Stephan

On Monday, January 7, 2013 2:30:13 AM UTC+1, Igor Motov wrote:

> Besides using the \_all field and index\_name attribute as Ivan suggested,  
> you can also use mutli\_match query to search multiple fields at the same  
> time:
> 
> ```
> "multi_match": {
> "query" : "your query goes here",
> "fields" : ["link*"]        
> }
> 
> ```
> 
> or use mutli\_field with "path": "just\_name" attribute to copy content of  
> several fields into a single field:  
> [Сopy multiple fields into a single field in ElasticSearch · GitHub](https://gist.github.com/6a96abda46d94847657d)
> 
> On Friday, January 4, 2013 12:29:00 PM UTC-5, Ivan Brusic wrote:
> 
> > I usually handle this behavior on the indexing side, outside of  
> > Elasticsearch. Related fields use the same field name.
> > 
> > Do you need the \_all field in general? If you don't, you can  
> > set include\_in\_all to false for every field except the link fields. If not,  
> > there is an index\_name setting in the mapping that I have never used. From  
> > the description, it sounds like it should support what you are looking for.  
> > Multi-field would not work since they are based off of the original field.
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/core-types.html)
> > 
> > --  
> > Ivan
> > 
> > On Fri, Jan 4, 2013 at 12:57 AM, Stephan Seidt [evilhac...@gmail.com](mailto:evilhac...@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > is it possible to have a field similar to \_all but with its own name and  
> > > only for specific fields of the source document?
> > > 
> > > As an example, two docs of the same type with two fields "linkA" and  
> > > "linkB" which should be mapped to \_links:
> > > 
> > > Doc 1: {"linkA": "[http://0000.com](http://0000.com)", "linkB": "[http://0001.com](http://0001.com)"}  
> > > Doc 2: {"linkA": "[http://0010.com](http://0010.com)", "linkB": "[http://0011.us](http://0011.us)"}
> > > 
> > > Now I don't want linkA and linkB to be included in \_all but, let's say,  
> > > in \_links so I can search for any link like this:
> > > 
> > > {"filter": {"term": {"\_links": "[http://0010.com](http://0010.com)"}}} -\> Doc 2
> > > 
> > > Is this perhaps possible by using multi\_field and mapping to an  
> > > identical \_links name for linkA and linkB?
> > > 
> > > Cheers  
> > > Stephan
> > > 
> > > --

--

---

<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:57am UTC](https://discuss.elastic.co/t/possible-to-have-something-like--all-with-own-name-for-specific-fields/10226/5 "2017-07-06T02:57:36Z")

</div>

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


