# Is it possible to query ordered string in Elasticsearch?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-query-ordered-string-in-elasticsearch/13579>\
**Category:** Elasticsearch\
**Created:** [September 12, 2013, 8:43pm UTC](https://discuss.elastic.co/t/is-it-possible-to-query-ordered-string-in-elasticsearch/13579 "2013-09-12T20:43:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11122](https://avatars.discourse-cdn.com/v4/letter/1/6a8cbe/32.png) [@11122](https://discuss.elastic.co/u/11122)\
**Post date:** [September 12, 2013, 8:43pm UTC](https://discuss.elastic.co/t/is-it-possible-to-query-ordered-string-in-elasticsearch/13579/1 "2013-09-12T20:43:46Z")

</div>

I'm wondering is it possible to query ordered string in Elasticsearch? For  
example, the query could be as follows

{  
"explain": true,  
"query": {  
"fuzzy\_like\_this": {  
"fields": [  
"domainElemString"  
],  
"like\_text": "engagement definition research resolution"  
}  
}  
}

and there are two docs with a value string of field "domainElemString", one  
value string is all the same with this like text and the words in the other  
one stated in different order, for instance, "definition engagement  
research resolution". I used flt query because it is based on edit  
distance, so I thought the doc with same field value should has the higher  
score than the other one. But the explanation in hits seems not so, the  
scores of these two docs are almost same except idf.

Am I missing something about FLT query? Is there any way to do such things?  
Thanks!

--  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [September 13, 2013, 9:33am UTC](https://discuss.elastic.co/t/is-it-possible-to-query-ordered-string-in-elasticsearch/13579/2 "2013-09-13T09:33:18Z")

</div>

Hiya

The FLT query doesn't take word position into account. The edit distance  
refers to changes to characters in a word, eg "resolutionS" -\> "resolution"  
has an edit distance of 1. This is the basis for "fuzzy" matching in Lucene  
and Elasticsearch.

If you want to take position into account, then you should use the  
"match\_phrase" query with a "slop" parameter (where slop is a bit like edit  
distance, but for word positions). Note: in a match\_phrase query, all  
words must be present, so you probably want to add this as a "should"  
clause inside a "bool" query. (ie if the match\_phrase clause matches, then  
it increases the score for that document, but it is not required to match)

clint

On 12 September 2013 22:43, 少爷允之 [chang.zhang29@googlemail.com](mailto:chang.zhang29@googlemail.com) wrote:

> I'm wondering is it possible to query ordered string in Elasticsearch? For  
> example, the query could be as follows
> 
> {  
> "explain": true,  
> "query": {  
> "fuzzy\_like\_this": {  
> "fields": [  
> "domainElemString"  
> ],  
> "like\_text": "engagement definition research resolution"  
> }  
> }  
> }
> 
> and there are two docs with a value string of field "domainElemString",  
> one value string is all the same with this like text and the words in the  
> other one stated in different order, for instance, "definition engagement  
> research resolution". I used flt query because it is based on edit  
> distance, so I thought the doc with same field value should has the higher  
> score than the other one. But the explanation in hits seems not so, the  
> scores of these two docs are almost same except idf.
> 
> Am I missing something about FLT query? Is there any way to do such  
> things? Thanks!
> 
> --  
> 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).

--  
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:** ![11122](https://avatars.discourse-cdn.com/v4/letter/1/6a8cbe/32.png) [@11122](https://discuss.elastic.co/u/11122)\
**Post date:** [September 15, 2013, 11:43am UTC](https://discuss.elastic.co/t/is-it-possible-to-query-ordered-string-in-elasticsearch/13579/3 "2013-09-15T11:43:14Z")

</div>

Thanks a lot, It works now.

在 2013年9月13日星期五UTC+2上午11时33分18秒，Clinton Gormley写道：

> Hiya
> 
> The FLT query doesn't take word position into account. The edit distance  
> refers to changes to characters in a word, eg "resolutionS" -\> "resolution"  
> has an edit distance of 1. This is the basis for "fuzzy" matching in Lucene  
> and Elasticsearch.
> 
> If you want to take position into account, then you should use the  
> "match\_phrase" query with a "slop" parameter (where slop is a bit like edit  
> distance, but for word positions). Note: in a match\_phrase query, all  
> words must be present, so you probably want to add this as a "should"  
> clause inside a "bool" query. (ie if the match\_phrase clause matches, then  
> it increases the score for that document, but it is not required to match)
> 
> clint
> 
> On 12 September 2013 22:43, 少爷允之 \<[chang....@googlemail.com](mailto:chang....@googlemail.com) \<javascript:\>\>wrote:
> 
> > I'm wondering is it possible to query ordered string in Elasticsearch?  
> > For example, the query could be as follows
> > 
> > {  
> > "explain": true,  
> > "query": {  
> > "fuzzy\_like\_this": {  
> > "fields": [  
> > "domainElemString"  
> > ],  
> > "like\_text": "engagement definition research resolution"  
> > }  
> > }  
> > }
> > 
> > and there are two docs with a value string of field "domainElemString",  
> > one value string is all the same with this like text and the words in the  
> > other one stated in different order, for instance, "definition engagement  
> > research resolution". I used flt query because it is based on edit  
> > distance, so I thought the doc with same field value should has the higher  
> > score than the other one. But the explanation in hits seems not so, the  
> > scores of these two docs are almost same except idf.
> > 
> > Am I missing something about FLT query? Is there any way to do such  
> > things? Thanks!
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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:16am UTC](https://discuss.elastic.co/t/is-it-possible-to-query-ordered-string-in-elasticsearch/13579/4 "2017-07-06T02:16:28Z")

</div>


