# Is Mapping per document level possible?

**URL:** <https://discuss.elastic.co/t/is-mapping-per-document-level-possible/8584>\
**Category:** Elasticsearch\
**Created:** [July 31, 2012, 5:26pm UTC](https://discuss.elastic.co/t/is-mapping-per-document-level-possible/8584 "2012-07-31T17:26:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajasuja18](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ajasuja18](https://discuss.elastic.co/u/ajasuja18)\
**Post date:** [July 31, 2012, 5:26pm UTC](https://discuss.elastic.co/t/is-mapping-per-document-level-possible/8584/1 "2012-07-31T17:26:13Z")

</div>

Hello Everyone,

One of my usecase is to support mapping at the document level i.e. each  
object to be indexed  
has a mapping associated with it.

Is it possible to have mapping at the per document basis? If yes, how can  
we do it using java api  
at runtime?

Thanks in advance..!!!

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [July 31, 2012, 6:24pm UTC](https://discuss.elastic.co/t/is-mapping-per-document-level-possible/8584/2 "2012-07-31T18:24:52Z")

</div>

My impression is routing is vary much intended to be per document.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

The routing information is typically defined in mapping and probably set  
to be required.  
See Routing on

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

shards can be configured to route documents with certain routing values  
to them

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

This is allocation is not required.

Then when a document is indexed routine information is either external  
to the document or part of the document.

The page

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Give an example where a comment document routed to a shard by its  
"blog.post\_id".  
Here is the routine part of the mapping for a comment document.

"{  
"comment" : {  
"\_routing" : {  
"required" : true,  
"path" : "blog.post\_id"  
}  
}  
}

Will cause the following doc to be routed based on the |111222| value:

{  
"text" : "the comment text"  
"blog" : {  
"post\_id" : "111222"  
}  
}"

The example suggests that blog posts also would be routed the same way,  
therefore the post and comments end up on the same shard.  
On which particular shard both the post and comments end up could be  
controlled by features described on the allocation page linked above.

Other examples on the ES site have all tweets for the same user routed  
using the same value (the example just use the user login id), so  
all the tweets end up together.

That's the long way to say that routing can be any value, so you can do  
anything you want on a per document basis.

-Paul

On 7/31/2012 10:26 AM, ajasuja wrote:

> Hello Everyone,
> 
> One of my usecase is to support mapping at the document level i.e.  
> each object to be indexed  
> has a mapping associated with it.
> 
> Is it possible to have mapping at the per document basis? If yes, how  
> can we do it using java api  
> at runtime?
> 
> Thanks in advance..!!!

---

<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:18am UTC](https://discuss.elastic.co/t/is-mapping-per-document-level-possible/8584/3 "2017-07-06T03:18:15Z")

</div>


