# Elasticsearch; Sequence searching in nested fields

**URL:** <https://discuss.elastic.co/t/elasticsearch-sequence-searching-in-nested-fields/107183>\
**Category:** Elasticsearch\
**Created:** [November 10, 2017, 12:13pm UTC](https://discuss.elastic.co/t/elasticsearch-sequence-searching-in-nested-fields/107183 "2017-11-10T12:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snigdha1292](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@snigdha1292](https://discuss.elastic.co/u/snigdha1292)\
**Post date:** [November 10, 2017, 12:13pm UTC](https://discuss.elastic.co/t/elasticsearch-sequence-searching-in-nested-fields/107183/1 "2017-11-10T12:13:10Z")

</div>

Hi,

I am trying to do a sequence searching in elastic search using nested fields.  
I have two fields:

1. Event Id:
2. Events - which is a nested field. This nested field has two fields:  
a) Id: Any number associated with the event  
b) Event Name: Name of the event happened

I am trying to see sequences in Event Names and want to return the Id of the first sequence match.  
Pasting my index mappings and the sorting that I have done till now.

Can somebody please suggest, how I can go about with the sequence search. Thanks in advance.

PUT nested\_events  
{  
"mappings": {  
"log": {  
"properties": {  
"Events": {  
"type": "nested"  
},  
"EventID":  
{  
"type" : "integer"  
}

```
  }
}

```

}  
}  
PUT /nested\_events/log/1  
{  
"EventID": 3,  
"Events": [  
{  
"Id": 10,  
"Event Name": "A"  
},  
{  
"Id": 11,  
"Event Name": "B"  
},  
{  
"Id": 12,  
"Event Name": "C"  
},  
{  
"Id": 13,  
"Event Name": "B"  
},{  
"Id": 14,  
"Event Name": "A"  
},  
{  
"Id": 15,  
"Event Name": "B"  
},  
{  
"Id": 16,  
"Event Name": "A"  
},  
{  
"Id": 17,  
"Event Name": "A"  
},  
{  
"Id": 18,  
"Event Name": "C"  
}

]  
}

And this is my sort query on the nested fields:  
GET /nested\_events/\_search  
{  
"sort": {  
"[Events.ID](http://Events.ID)": {  
"order": "asc",  
"mode": "min"  
}  
}

Input: AB  
Expected Output:  
Id: 10  
Id: 14

---

<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:** [December 8, 2017, 12:13pm UTC](https://discuss.elastic.co/t/elasticsearch-sequence-searching-in-nested-fields/107183/2 "2017-12-08T12:13:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
