# How to search with specific keyword order

**URL:** <https://discuss.elastic.co/t/how-to-search-with-specific-keyword-order/38293>\
**Category:** Elasticsearch\
**Created:** [January 4, 2016, 7:00am UTC](https://discuss.elastic.co/t/how-to-search-with-specific-keyword-order/38293 "2016-01-04T07:00:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hacksign](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hacksign/32/5918_2.png) [@Hacksign](https://discuss.elastic.co/u/Hacksign)\
**Post date:** [January 4, 2016, 7:00am UTC](https://discuss.elastic.co/t/how-to-search-with-specific-keyword-order/38293/1 "2016-01-04T07:00:35Z")

</div>

If there is an data like below :

`this is a test line contain notepad.exe.`  
`this is not the line I want which contain notepad.exe for test`

and hypothesis, I dont know all words in above sentence, what I know is below :

1. the sentence contains keyword 'test'
2. the sentence contains keyword 'notepad.exe'
3. keyword is in strict order: 'exe' after 'notepad', 'notepad' after 'test'
4. all keywords may not consecutively

Because reason 4, I can not use match\_phrase query,so is there any way I can pick out first line with DSL query ?

---

<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, 2016, 9:02pm UTC](https://discuss.elastic.co/t/how-to-search-with-specific-keyword-order/38293/2 "2016-01-04T21:02:05Z")

</div>

Look into span queries. They are not very performant, but offer loads more  
flexibility than standard phrase queries.

[https://www.elastic.co/guide/en/elasticsearch/reference/master/span-queries.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/span-queries.html)

---

<div class="post-metadata">

**Author:** ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)\
**Post date:** [January 4, 2016, 10:08pm UTC](https://discuss.elastic.co/t/how-to-search-with-specific-keyword-order/38293/3 "2016-01-04T22:08:15Z")

</div>

Hi,

You can also do this:

```auto
{
  "query": {
    "query_string": {
      "query": "\"test notepad.exe\"~2",
      "default_operator": "AND"
    
    }
  }
}

```

[https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-query-string-query.html#\_proximity\_searches](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-query-string-query.html#_proximity_searches)

---

<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 5, 2017, 11:27pm UTC](https://discuss.elastic.co/t/how-to-search-with-specific-keyword-order/38293/4 "2017-07-05T23:27:14Z")

</div>


