# Search hit multivalued field

**URL:** <https://discuss.elastic.co/t/search-hit-multivalued-field/7629>\
**Category:** Elasticsearch\
**Created:** [May 10, 2012, 10:00am UTC](https://discuss.elastic.co/t/search-hit-multivalued-field/7629 "2012-05-10T10:00:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmz/32/2842_2.png) [@nmz](https://discuss.elastic.co/u/nmz)\
**Post date:** [May 10, 2012, 10:00am UTC](https://discuss.elastic.co/t/search-hit-multivalued-field/7629/1 "2012-05-10T10:00:07Z")

</div>

Say I have a multivalued field(student[studentid, name]) in my  
document[1234] with the following values :

```
[1,bob]
[2,alice]
[3,carl]
[4,scott]

```

I search for 'alice' and I get hit for doc: 1234.

From the searchHit is it possible to retrieve the 'studentId' for  
which i got the hit? [In this case '2' corresponding to alice]

note: studentId[store : yes]

---

<div class="post-metadata">

**Author:** ![nmz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmz/32/2842_2.png) [@nmz](https://discuss.elastic.co/u/nmz)\
**Post date:** [May 10, 2012, 11:31am UTC](https://discuss.elastic.co/t/search-hit-multivalued-field/7629/2 "2012-05-10T11:31:14Z")

</div>

Currently it cannot be done with Elasticsearch.

On May 10, 3:00 pm, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) wrote:

> Say I have a multivalued field(student[studentid, name]) in my  
> document[1234] with the following values :
> 
> ```
> [1,bob]
> [2,alice]
> [3,carl]
> [4,scott]
> 
> ```
> 
> I search for 'alice' and I get hit for doc: 1234.
> 
> From the searchHit is it possible to retrieve the 'studentId' for  
> which i got the hit? [In this case '2' corresponding to alice]
> 
> note: studentId[store : yes]

---

<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:** [May 10, 2012, 11:40am UTC](https://discuss.elastic.co/t/search-hit-multivalued-field/7629/3 "2012-05-10T11:40:54Z")

</div>

Does the parent / child or nested docs could help you ?  
Does the highlight function could help you ?

Another idea could be to store a "technical" field (or use multifield), and  
put in it something like "1:bob" with a keyword analyzer (or no analyzer at  
all) and highlight this field.

BTW, if you are looking for students, why are you indexing documents ?

HTH  
David.

Le 10 mai 2012 à 13:31, nmz [s.namitha.s@gmail.com](mailto:s.namitha.s@gmail.com) a écrit :

> Currently it cannot be done with Elasticsearch.
> 
> On May 10, 3:00 pm, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) wrote:
> 
> > Say I have a multivalued field(student[studentid, name]) in my  
> > document[1234] with the following values :
> > 
> > ```
> > [1,bob]
> > [2,alice]
> > [3,carl]
> > [4,scott]
> > 
> > ```
> > 
> > I search for 'alice' and I get hit for doc: 1234.
> > 
> > From the searchHit is it possible to retrieve the 'studentId' for  
> > which i got the hit? [In this case '2' corresponding to alice]
> > 
> > note: studentId[store : yes]

--  
David Pilato  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![nmz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmz/32/2842_2.png) [@nmz](https://discuss.elastic.co/u/nmz)\
**Post date:** [May 11, 2012, 9:45am UTC](https://discuss.elastic.co/t/search-hit-multivalued-field/7629/4 "2012-05-11T09:45:11Z")

</div>

I am not sure if it is a good idea to create parent child document,  
where in I dont require any fields in the parent mapping.  
The highlight function just helps me in the highlighting part. I need  
to retrieve the id [not for displaying], for verification.

The student was just an example to state my problem, not my real  
issue..

On May 10, 4:40 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> Does the parent / child or nested docs could help you ?  
> Does the highlight function could help you ?
> 
> Another idea could be to store a "technical" field (or use multifield), and  
> put in it something like "1:bob" with a keyword analyzer (or no analyzer at  
> all) and highlight this field.
> 
> BTW, if you are looking for students, why are you indexing documents ?
> 
> HTH  
> David.
> 
> Le 10 mai 2012 à 13:31, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) a écrit :
> 
> > Currently it cannot be done with Elasticsearch.
> 
> > On May 10, 3:00 pm, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) wrote:
> > 
> > > Say I have a multivalued field(student[studentid, name]) in my  
> > > document[1234] with the following values :
> 
> > > ```
> > > [1,bob]
> > > [2,alice]
> > > [3,carl]
> > > [4,scott]
> > > 
> > > ```
> 
> > > I search for 'alice' and I get hit for doc: 1234.
> 
> > > From the searchHit is it possible to retrieve the 'studentId' for  
> > > which i got the hit? [In this case '2' corresponding to alice]
> 
> > > note: studentId[store : yes]
> 
> --  
> David Pilatohttp://dev.david.pilato.fr/  
> Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Amarthya\_Master](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Amarthya\_Master](https://discuss.elastic.co/u/Amarthya_Master)\
**Post date:** [March 19, 2013, 6:59am UTC](https://discuss.elastic.co/t/search-hit-multivalued-field/7629/5 "2013-03-19T06:59:12Z")

</div>

Did you implement a solution for this? I have a similar need where in  
search needs to happen on a field in a multi valued object, but from the  
hit highlights I would like to identify which object in the multi valued  
field got the match. Basically instead of just the hightlight fragments,  
would like to get back additional fields (for example, a unique id  
associated with the field in the multi valued object) included in the  
highlights results.

Thinking of extending highlights query syntax such that you can specify  
additional decorator fields along with the field you want to highlight.  
These fields and the values of the fields will then be included in each  
hightlight fragment. Say a Key/Value pair of FieldName and FieldValue of  
all the aditional data. That would allow one to include the "id" field in  
my use case along with the hit highlights.

Let me know if it makes sense, and I would go ahead and implement this.

On Friday, May 11, 2012 2:45:11 AM UTC-7, nmz wrote:

> I am not sure if it is a good idea to create parent child document,  
> where in I dont require any fields in the parent mapping.  
> The highlight function just helps me in the highlighting part. I need  
> to retrieve the id [not for displaying], for verification.
> 
> The student was just an example to state my problem, not my real  
> issue..
> 
> On May 10, 4:40 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > Does the parent / child or nested docs could help you ?  
> > Does the highlight function could help you ?
> > 
> > Another idea could be to store a "technical" field (or use multifield),  
> > and  
> > put in it something like "1:bob" with a keyword analyzer (or no analyzer  
> > at  
> > all) and highlight this field.
> > 
> > BTW, if you are looking for students, why are you indexing documents ?
> > 
> > HTH  
> > David.
> > 
> > Le 10 mai 2012 à 13:31, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) a écrit :
> > 
> > > Currently it cannot be done with Elasticsearch.
> > 
> > > On May 10, 3:00 pm, nmz [s.namith...@gmail.com](mailto:s.namith...@gmail.com) wrote:
> > > 
> > > > Say I have a multivalued field(student[studentid, name]) in my  
> > > > document[1234] with the following values :
> > 
> > > > ```
> > > > [1,bob] 
> > > > [2,alice] 
> > > > [3,carl] 
> > > > [4,scott] 
> > > > 
> > > > ```
> > 
> > > > I search for 'alice' and I get hit for doc: 1234.
> > 
> > > > From the searchHit is it possible to retrieve the 'studentId' for  
> > > > which i got the hit? [In this case '2' corresponding to alice]
> > 
> > > > note: studentId[store : yes]
> > 
> > --  
> > David Pilatohttp://dev.david.pilato.fr/  
> > Twitter : @dadoonet

--  
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:45am UTC](https://discuss.elastic.co/t/search-hit-multivalued-field/7629/6 "2017-07-06T02:45:54Z")

</div>


