# Query on \_content\_type?

**URL:** <https://discuss.elastic.co/t/query-on--content-type/6691>\
**Category:** Elasticsearch\
**Created:** [February 13, 2012, 6:41pm UTC](https://discuss.elastic.co/t/query-on--content-type/6691 "2012-02-13T18:41:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nurikabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nurikabe/32/2192_2.png) [@nurikabe](https://discuss.elastic.co/u/nurikabe)\
**Post date:** [February 13, 2012, 6:41pm UTC](https://discuss.elastic.co/t/query-on--content-type/6691/1 "2012-02-13T18:41:34Z")

</div>

I think I'm overlooking something obvious here. If I have data indexed  
with the mapper-attachment like so:

{

- \_index: index
- \_type: type
- \_id: s8SSO7frShGcVH8P8rSaaw
- \_version: 1
- \_score: 1
- \_source: {
  - id: { ... }
  - user: { ... }
  - date\_created: 1321286179
  - date\_updated: 1321286179
  - visibility: visible
  - title: Linguiste
  - file: {
    - \_content\_type: application/pdf
    - content:JVBERi0xLjUNCiW1tbW...  
}  
}

}

how can I query on content type? I thought I would be able to do something  
like:

{  
"query": {  
"term": {  
"file.\_content\_type": "pdf"  
}  
}  
}

but no dice. Where am I going wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 14, 2012, 2:08pm UTC](https://discuss.elastic.co/t/query-on--content-type/6691/2 "2012-02-14T14:08:36Z")

</div>

Its called content\_type, or in your case, file.content\_type should work. The \_content\_type option in the json is a hint to the parser (which might be able to derive it automatically if not provided), and then its indexed under content\_type.

On Monday, February 13, 2012 at 8:41 PM, nurikabe wrote:

> I think I'm overlooking something obvious here. If I have data indexed with the mapper-attachment like so:
> 
> {  
> \_index: index  
> \_type: type  
> \_id: s8SSO7frShGcVH8P8rSaaw  
> \_version: 1  
> \_score: 1  
> \_source: {  
> id: { ... }  
> user: { ... }  
> date\_created: 1321286179  
> date\_updated: 1321286179  
> visibility: visible  
> title: Linguiste  
> file: {  
> \_content\_type: application/pdf  
> content:JVBERi0xLjUNCiW1tbW...
> 
> }
> 
> }
> 
> }
> 
> how can I query on content type? I thought I would be able to do something like:
> 
> {  
> "query": {  
> "term": {  
> "file.\_content\_type": "pdf"  
> }  
> }  
> }
> 
> but no dice. Where am I going wrong?
> 
> Thanks!

---

<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:39am UTC](https://discuss.elastic.co/t/query-on--content-type/6691/3 "2017-07-06T03:39:26Z")

</div>

Closed on July 6, 2017, 3:39am UTC


