# Modelling data and query

**URL:** <https://discuss.elastic.co/t/modelling-data-and-query/151633>\
**Category:** Elasticsearch\
**Created:** [October 9, 2018, 12:38pm UTC](https://discuss.elastic.co/t/modelling-data-and-query/151633 "2018-10-09T12:38:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellonde](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ellonde](https://discuss.elastic.co/u/ellonde)\
**Post date:** [October 9, 2018, 12:38pm UTC](https://discuss.elastic.co/t/modelling-data-and-query/151633/1 "2018-10-09T12:38:24Z")

</div>

Hello there,

Im pretty new to the ES stack and im not quite sure how to model my problem, right now it seems like an endless amount of options for modelling the queries and data.

The case is quite simple: I have a bunch of document, plain text pieces. I want to find the phrase(e.g. sentence) within all documents that matches the query best. I also have some additional information keyword information on document level which I haven't considered completely yet.

In broad term: I would like to find the best phrases, where the context of the document is taken into account. But im not sure both how to model the data and how to create "optimal" queries(as this probably depend on the model structure).

As i see it, I could model the data as just the sentences separately. But that way i feel like there is some context signal that gets lost from the other phrases in the document and the document keywords.

Hope you guys have some input 🙂

EDIT:

So far I have modelled it as phrase index with the document as a field and then used a multi\_match query where I boost the phrase field.

Any inputs are still very welcome!

Best regards  
Mathias

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [October 11, 2018, 8:41am UTC](https://discuss.elastic.co/t/modelling-data-and-query/151633/2 "2018-10-11T08:41:21Z")

</div>

Hi Mathias,

As you mentioned in your post, indexing the text of the document as a field and using the multi\_match (or match) query with the `type: phrase` sounds exactly like what you are looking for.

Another thing you could look into if you were interested are shingles, this would allow you to do cheaper phrase queries (assuming you don't need slop), but otherwise, you are on the right track.

---

<div class="post-metadata">

**Author:** ![ellonde](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ellonde](https://discuss.elastic.co/u/ellonde)\
**Post date:** [October 11, 2018, 9:43am UTC](https://discuss.elastic.co/t/modelling-data-and-query/151633/3 "2018-10-11T09:43:28Z")

</div>

Thank you for your reply.

Just knowing that im on the right track is quite helpful with the amount of possibilities available in ES.

Ill look into shingles 🙂

Best regards  
Mathias

---

<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:** [November 8, 2018, 9:48am UTC](https://discuss.elastic.co/t/modelling-data-and-query/151633/4 "2018-11-08T09:48:57Z")

</div>

Closed on November 8, 2018, 9:48am UTC

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