# Search for a sequence

**URL:** <https://discuss.elastic.co/t/search-for-a-sequence/15772>\
**Category:** Elasticsearch\
**Created:** [February 13, 2014, 5:11am UTC](https://discuss.elastic.co/t/search-for-a-sequence/15772 "2014-02-13T05:11:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vasil\_Remeniuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vasil_remeniuk/32/1797_2.png) [@Vasil\_Remeniuk](https://discuss.elastic.co/u/Vasil_Remeniuk)\
**Post date:** [February 13, 2014, 5:11am UTC](https://discuss.elastic.co/t/search-for-a-sequence/15772/1 "2014-02-13T05:11:26Z")

</div>

Hello,

I have a collection of strings with ordered user events, produced by a 3rd  
party system, that looks like this:

USER A -\> 10:1 11 10:2 10:3 1201:1  
USER B -\> 10:1 10:2 10:3 10:4

, where every word is an event, generated by that user.

Event has a following format:

\<event ID, 2 digits\>\<related item ID, 2 digits\>:\<amount, any number of digits\>

With ElasticSearch I want to count all documents (users) that have a  
certain sequence of events:

10 -\> 10 -\> 10  
10:1 -\> 10:3  
11 -\> 1201

In some cases I need to search by event ID, only - item ID and amount are  
optional.

What is the proper way to achieve that in ElasticSearch?

Currently, I store those sequences in MongoDB, and perform search/count  
with complex regexes.

Thank you!

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8d5cd78d-af67-4a71-8a37-2948e083c3ea%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8d5cd78d-af67-4a71-8a37-2948e083c3ea%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 13, 2014, 1:51pm UTC](https://discuss.elastic.co/t/search-for-a-sequence/15772/2 "2014-02-13T13:51:30Z")

</div>

Not quite sure I understand 100% the requirements. So if I have these 2  
documents:

Doc 1 -\> 10:1 11 10:2 10:3 1201:1  
Doc 2 -\> 10:1 10:2 10:3 10:4

What would each of these queries return?

1. 10 11 10
2. 10 10 10
3. 10 10 11
4. 10 12
5. 10:3 1201

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f97c11a0-5b1e-4a64-8574-4c71054cc9e1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f97c11a0-5b1e-4a64-8574-4c71054cc9e1%40googlegroups.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, 1:50am UTC](https://discuss.elastic.co/t/search-for-a-sequence/15772/3 "2017-07-06T01:50:30Z")

</div>


