# How to get position of matched token

**URL:** https://discuss.elastic.co/t/how-to-get-position-of-matched-token/247521
**Category:** Elasticsearch
**Created:** [September 4, 2020, 11:02am UTC](https://discuss.elastic.co/t/how-to-get-position-of-matched-token/247521 "2020-09-04T11:02:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![drewblin](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@drewblin](https://discuss.elastic.co/u/drewblin)
#### Post date: [September 4, 2020, 11:02am UTC](https://discuss.elastic.co/t/how-to-get-position-of-matched-token/247521/1 "2020-09-04T11:02:29Z")

</div>

Hi  
I want to migrate from Sphinxsearch to Elastic. But have task, that i don't know how to solve in elastic.

I have documents with 2 fields.  
First field - "title". It is array of words. And each word can have some synonyms.  
Second field - "ids". It is array of ids, corresponding to words on same index.

For example:

```auto
title = [["word1", "syn11", "syn12"], ["word2", "syn21"], ["word3"] ]
ids = [101, 102, 103]

```

id = 101 corresponds to word1, 102 - to word2, ...

I need to find documents that match some phrase by field "title". And for that documents get id from "ids" field that corresponds to last matched word. And all that should be done in elastic only (not to use some other applications to process intermediate result).

For example:

1. match to "word3 syn11" should return 103
2. match to "word1 syn21" should return 102

In Sphinxsearch I combined all words to string like "word1 syn11 syn12 . word2 syn21 . word3". Then config indexer to process point "." as sentence separator with shifting position on 1000 words. And during search I changed ranking to return maximum position of matched token.

But i there some solution for my task in elastic? I could not find any similar configuration in tokenizers. And only thing I found - I need to write custom plugin to get access to matched token indexes in ranking result.

Help me, please

---

<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: [October 2, 2020, 11:02am UTC](https://discuss.elastic.co/t/how-to-get-position-of-matched-token/247521/2 "2020-10-02T11:02:33Z")

</div>

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