# How to correctly store documents with page numbers?

**URL:** <https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305>\
**Category:** Elasticsearch\
**Created:** [April 12, 2012, 10:08am UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305 "2012-04-12T10:08:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vitaly](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@Vitaly](https://discuss.elastic.co/u/Vitaly)\
**Post date:** [April 12, 2012, 10:08am UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305/1 "2012-04-12T10:08:41Z")

</div>

Hi,

I was wondering if someone could help me with one issue. What would be  
the best way to store document in a way that I could get original  
document page number from elastic search? What happens now is I store  
page number as field name in elastic search. Everything works well,  
except one issue: highlighting. As you know in order for highlighting  
to work, you have to supply field name, and in my case I'm not sure on  
which page the result will be -\> no way to supply field name.

So quickly what I'm trying to achieve:

I need to store document in elastic search, get corresponding page  
number in results and have search hits highlighted.

Cheers,  
Vitaly

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [April 12, 2012, 10:39am UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305/2 "2012-04-12T10:39:44Z")

</div>

Hi,

not sure I fully understand where is your problem. Do you think you can  
share more info about how you model your domain objects? For example: you  
break the book by pages and index each page as a separated document into ES?

Regards,  
Lukas

On Thu, Apr 12, 2012 at 12:08 PM, Vitaly [vshestovskiy@gmail.com](mailto:vshestovskiy@gmail.com) wrote:

> Hi,
> 
> I was wondering if someone could help me with one issue. What would be  
> the best way to store document in a way that I could get original  
> document page number from Elasticsearch? What happens now is I store  
> page number as field name in Elasticsearch. Everything works well,  
> except one issue: highlighting. As you know in order for highlighting  
> to work, you have to supply field name, and in my case I'm not sure on  
> which page the result will be -\> no way to supply field name.
> 
> So quickly what I'm trying to achieve:
> 
> I need to store document in Elasticsearch, get corresponding page  
> number in results and have search hits highlighted.
> 
> Cheers,  
> Vitaly

---

<div class="post-metadata">

**Author:** ![Vitaly](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@Vitaly](https://discuss.elastic.co/u/Vitaly)\
**Post date:** [April 12, 2012, 10:54am UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305/3 "2012-04-12T10:54:41Z")

</div>

Hi Lukas,

Right now I create new document in Elasticsearch for each book, and  
then store separate pages in the document, with page number as field  
name. Something like this:

{  
"\_index" : "data",  
"\_type" : "documents",  
"\_id" : "1",  
"\_source" : {  
"title" : "Document name",  
"1" : "Page 1 data",  
"2" : "Page 2 data"  
}  
}

Cheers,  
Vitaly

On Apr 12, 1:39 pm, Lukáš Vlček [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:

> Hi,
> 
> not sure I fully understand where is your problem. Do you think you can  
> share more info about how you model your domain objects? For example: you  
> break the book by pages and index each page as a separated document into ES?
> 
> Regards,  
> Lukas
> 
> On Thu, Apr 12, 2012 at 12:08 PM, Vitaly [vshestovs...@gmail.com](mailto:vshestovs...@gmail.com) wrote:
> 
> > Hi,
> 
> > I was wondering if someone could help me with one issue. What would be  
> > the best way to store document in a way that I could get original  
> > document page number from Elasticsearch? What happens now is I store  
> > page number as field name in Elasticsearch. Everything works well,  
> > except one issue: highlighting. As you know in order for highlighting  
> > to work, you have to supply field name, and in my case I'm not sure on  
> > which page the result will be -\> no way to supply field name.
> 
> > So quickly what I'm trying to achieve:
> 
> > I need to store document in Elasticsearch, get corresponding page  
> > number in results and have search hits highlighted.
> 
> > Cheers,  
> > Vitaly

---

<div class="post-metadata">

**Author:** ![chenguohui](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@chenguohui](https://discuss.elastic.co/u/chenguohui)\
**Post date:** [April 12, 2012, 1:22pm UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305/4 "2012-04-12T13:22:26Z")

</div>

Hi Vitaly  
Why not separate it? One page per doc in es.  
{  
"\_index" : "data",  
"\_type" : "documents",  
"\_id" : "1",  
"\_source" : {  
"title" : "Document name",  
"content" : "Page 1 data",  
"pageNum" : 1  
}  
}

---

<div class="post-metadata">

**Author:** ![Vitaly](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@Vitaly](https://discuss.elastic.co/u/Vitaly)\
**Post date:** [April 13, 2012, 1:54pm UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305/5 "2012-04-13T13:54:21Z")

</div>

But in that case I will get results weighted by page, not by document,  
no?

On Apr 12, 4:22 pm, chenguohui [trgo...@gmail.com](mailto:trgo...@gmail.com) wrote:

> Hi Vitaly  
> Why not separate it? One page per doc in es.  
> {  
> "\_index" : "data",  
> "\_type" : "documents",  
> "\_id" : "1",  
> "\_source" : {  
> "title" : "Document name",  
> "content" : "Page 1 data",  
> "pageNum" : 1  
> }
> 
> }

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 13, 2012, 4:31pm UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305/6 "2012-04-13T16:31:41Z")

</div>

What about using parent/chlid feature :  
Parent is the document  
Children are pages

Not sure that it will help 😉

David.

> -----Message d'origine-----  
> De : [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
> [[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] De la part de Vitaly  
> Envoyé : vendredi 13 avril 2012 15:54  
> À : elasticsearch  
> Objet : Re: How to correctly store documents with page numbers?
> 
> But in that case I will get results weighted by page, not by document,  
> no?
> 
> On Apr 12, 4:22 pm, chenguohui [trgo...@gmail.com](mailto:trgo...@gmail.com) wrote:
> 
> > Hi Vitaly  
> > Why not separate it? One page per doc in es.  
> > {  
> > "\_index" : "data",  
> > "\_type" : "documents",  
> > "\_id" : "1",  
> > "\_source" : {  
> > "title" : "Document name",  
> > "content" : "Page 1 data",  
> > "pageNum" : 1  
> > }
> > 
> > }

---

<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, 3:32am UTC](https://discuss.elastic.co/t/how-to-correctly-store-documents-with-page-numbers/7305/7 "2017-07-06T03:32:39Z")

</div>


