# How to access document type in script?

**URL:** https://discuss.elastic.co/t/how-to-access-document-type-in-script/14815
**Category:** Elasticsearch
**Created:** [December 11, 2013, 1:36pm UTC](https://discuss.elastic.co/t/how-to-access-document-type-in-script/14815 "2013-12-11T13:36:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)
#### Post date: [December 11, 2013, 1:36pm UTC](https://discuss.elastic.co/t/how-to-access-document-type-in-script/14815/1 "2013-12-11T13:36:10Z")

</div>

Hi,

I'm using custom score query with script which should access object type of  
document.  
I want to search on more document types (same index), but not all types in  
same index and for example, increment score of document if it is in array  
of types.

How can I do this? Is there way to access to type of document in scriot,  
something like:

doc['field'].type or similar ?

Thanks in advance

--  
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/fbfcb372-d25a-46a8-8eb2-ebad1b19f34b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbfcb372-d25a-46a8-8eb2-ebad1b19f34b%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: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [December 11, 2013, 7:12pm UTC](https://discuss.elastic.co/t/how-to-access-document-type-in-script/14815/2 "2013-12-11T19:12:11Z")

</div>

I have never tried doing so, but doc['\_type'].value should work.

What would probably work for your is a custom score filter using a filter  
on the \_type field.

elasticsearch 0.90.4+  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#\_score\_functions](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_score_functions)

elasticsearch 0.90.3 and before

> **[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.

--  
Ivan

On Wed, Dec 11, 2013 at 5:36 AM, aldm [amer.zildzic@gmail.com](mailto:amer.zildzic@gmail.com) wrote:

> Hi,
> 
> I'm using custom score query with script which should access object type  
> of document.  
> I want to search on more document types (same index), but not all types in  
> same index and for example, increment score of document if it is in array  
> of types.
> 
> How can I do this? Is there way to access to type of document in scriot,  
> something like:
> 
> doc['field'].type or similar ?
> 
> Thanks in advance
> 
> --  
> 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/fbfcb372-d25a-46a8-8eb2-ebad1b19f34b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbfcb372-d25a-46a8-8eb2-ebad1b19f34b%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CALY%3DcQDBDGOyx-q62gihF9c9EP3oi-3uzj%2BsT7F\_hA9MKFmU2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDBDGOyx-q62gihF9c9EP3oi-3uzj%2BsT7F_hA9MKFmU2Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)
#### Post date: [December 16, 2013, 9:29am UTC](https://discuss.elastic.co/t/how-to-access-document-type-in-script/14815/3 "2013-12-16T09:29:23Z")

</div>

It works. Thank you very much.

On Wednesday, December 11, 2013 2:36:10 PM UTC+1, aldm wrote:

> Hi,
> 
> I'm using custom score query with script which should access object type  
> of document.  
> I want to search on more document types (same index), but not all types in  
> same index and for example, increment score of document if it is in array  
> of types.
> 
> How can I do this? Is there way to access to type of document in scriot,  
> something like:
> 
> doc['field'].type or similar ?
> 
> Thanks in advance

--  
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/2d2cff27-2523-4e4c-a003-ef2b87c70ce9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2d2cff27-2523-4e4c-a003-ef2b87c70ce9%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, 2:01am UTC](https://discuss.elastic.co/t/how-to-access-document-type-in-script/14815/4 "2017-07-06T02:01:04Z")

</div>


