# Query phrase order

**URL:** <https://discuss.elastic.co/t/query-phrase-order/156061>\
**Category:** Elasticsearch\
**Created:** [November 9, 2018, 2:00pm UTC](https://discuss.elastic.co/t/query-phrase-order/156061 "2018-11-09T14:00:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelothebuilder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcelothebuilder/32/37522_2.png) [@marcelothebuilder](https://discuss.elastic.co/u/marcelothebuilder)\
**Post date:** [November 9, 2018, 2:00pm UTC](https://discuss.elastic.co/t/query-phrase-order/156061/1 "2018-11-09T14:00:58Z")

</div>

I have a specific query where I will need to find phrases before others considering a start and end field representing seconds in a timeline.

The index mapping:  
{  
"thetext": {  
"mappings": {  
"thetext": {  
"properties": {  
"sentences": {  
"type": "nested",  
"properties": {  
"end": {  
"type": "double"  
},  
"speaker": {  
"type": "integer"  
},  
"start": {  
"type": "double"  
},  
"text": {  
"type": "text"  
}  
}  
}  
}  
}  
}  
}  
}

Example of a doc:  
{  
"sentences": [  
{  
"sentenceId": 1,  
"speaker": 1,  
"start": 0.2,  
"end": 0.9,  
"text": "Hi"  
},  
{  
"sentenceId": 2,  
"speaker": 2,  
"start": 1.5,  
"end": 2.46,  
"text": "Hello, good morning"  
},  
{  
"sentenceId": 3,  
"speaker": 1,  
"start": 3.32,  
"end": 6.88,  
"text": "I wish to talk to your manager"  
},  
{  
"sentenceId": 4,  
"speaker": 2,  
"start": 8.18,  
"end": 23.27,  
"text": "It won't be possible. He's not here."  
},  
{  
"sentenceId": 5,  
"speaker": 1,  
"start": 23.51,  
"end": 24.79,  
"text": "Okay, thank you."  
},  
{  
"sentenceId": 6,  
"speaker": 2,  
"start": 25.07,  
"end": 25.51,  
"text": "Bye bye"  
}  
]  
}

What I want to search is, for example, docs that the phrase "thank you" occurs after "bye bye", but this can happen in different nested docs (that's why I must consider the start and end fields) OR in the same doc.

Is this possible using standard elasticsearch features? If not, would it be possible with a custom plugin?

---

<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 7, 2018, 2:01pm UTC](https://discuss.elastic.co/t/query-phrase-order/156061/2 "2018-12-07T14:01:13Z")

</div>

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