# Mapping for multiple types under one index

**URL:** <https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006>\
**Category:** Elasticsearch\
**Created:** [July 31, 2011, 1:17pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006 "2011-07-31T13:17:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sophia\_parafina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sophia_parafina/32/3158_2.png) [@sophia\_parafina](https://discuss.elastic.co/u/sophia_parafina)\
**Post date:** [July 31, 2011, 1:17pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/1 "2011-07-31T13:17:04Z")

</div>

Is there an example for mapping multiple geo\_point types under one  
index. I've searched the group for examples but all of them are for  
single types and those work, but I can't get the correct syntax for  
multiple types.

sophia

---

<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:** [July 31, 2011, 2:58pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/2 "2011-07-31T14:58:45Z")

</div>

You mean having several fields in the json of type geo\_point? Something like  
this: [gist:1116858 · GitHub](https://gist.github.com/1116858)? If not, then gist the sample json you  
want to map.

On Sun, Jul 31, 2011 at 4:17 PM, sophiap [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com) wrote:

> Is there an example for mapping multiple geo\_point types under one  
> index. I've searched the group for examples but all of them are for  
> single types and those work, but I can't get the correct syntax for  
> multiple types.
> 
> sophia

---

<div class="post-metadata">

**Author:** ![sophia\_parafina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sophia_parafina/32/3158_2.png) [@sophia\_parafina](https://discuss.elastic.co/u/sophia_parafina)\
**Post date:** [July 31, 2011, 3:48pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/3 "2011-07-31T15:48:35Z")

</div>

Hmmm, I think I don't understand what is meant by type, judging from  
you example. I meant something like this [gist:1116899 · GitHub](https://gist.github.com/1116899)

On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> You mean having several fields in the json of type geo\_point? Something like  
> this:[gist:1116858 · GitHub](https://gist.github.com/1116858?If) not, then gist the sample json you  
> want to map.
> 
> On Sun, Jul 31, 2011 at 4:17 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com) wrote:
> 
> > Is there an example for mapping multiple geo\_point types under one  
> > index. I've searched the group for examples but all of them are for  
> > single types and those work, but I can't get the correct syntax for  
> > multiple types.
> 
> > sophia

---

<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:** [July 31, 2011, 4:01pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/4 "2011-07-31T16:01:57Z")

</div>

The mapping you gisted looks good, what is not working? Maybe you can gist a  
sample of what does not work for you? ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).

On Sun, Jul 31, 2011 at 6:48 PM, sophiap [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com) wrote:

> Hmmm, I think I don't understand what is meant by type, judging from  
> you example. I meant something like this [gist:1116899 · GitHub](https://gist.github.com/1116899)
> 
> On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > You mean having several fields in the json of type geo\_point? Something  
> > like  
> > this:[gist:1116858 · GitHub](https://gist.github.com/1116858?If) not, then gist the sample json  
> > you  
> > want to map.
> > 
> > On Sun, Jul 31, 2011 at 4:17 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > wrote:
> > 
> > > Is there an example for mapping multiple geo\_point types under one  
> > > index. I've searched the group for examples but all of them are for  
> > > single types and those work, but I can't get the correct syntax for  
> > > multiple types.
> > 
> > > sophia

---

<div class="post-metadata">

**Author:** ![sophia\_parafina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sophia_parafina/32/3158_2.png) [@sophia\_parafina](https://discuss.elastic.co/u/sophia_parafina)\
**Post date:** [July 31, 2011, 4:19pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/5 "2011-07-31T16:19:43Z")

</div>

Sorry, I should have attached the error I get when I save the mapping  
to a file and register it.

curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'

curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json

{"error":"ActionRequestValidationException[Validation Failed: 1:  
mapping type is missing;]","status":500}

On Jul 31, 11:01 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> The mapping you gisted looks good, what is not working? Maybe you can gist a  
> sample of what does not work for you? ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> 
> On Sun, Jul 31, 2011 at 6:48 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com) wrote:
> 
> > Hmmm, I think I don't understand what is meant by type, judging from  
> > you example. I meant something like thishttps://gist.github.com/1116899
> 
> > On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > You mean having several fields in the json of type geo\_point? Something  
> > > like  
> > > this:[gist:1116858 · GitHub](https://gist.github.com/1116858?Ifnot), then gist the sample json  
> > > you  
> > > want to map.
> 
> > > On Sun, Jul 31, 2011 at 4:17 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > > wrote:
> > > 
> > > > Is there an example for mapping multiple geo\_point types under one  
> > > > index. I've searched the group for examples but all of them are for  
> > > > single types and those work, but I can't get the correct syntax for  
> > > > multiple types.
> 
> > > > sophia

---

<div class="post-metadata">

**Author:** ![jp\_lorandi](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jp\_lorandi](https://discuss.elastic.co/u/jp_lorandi)\
**Post date:** [July 31, 2011, 4:25pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/6 "2011-07-31T16:25:49Z")

</div>

You're just missing the mapping type's name; your curl line should be:

curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json

Also, afaik, if you're sending a file with -d, you need to prepend the name with @ thus

curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json

HTH,JP

> -------- Original Message --------
> 
> Subject: Re: Mapping for multiple types under one index
> 
> From: sophiap \<[sophia.parafina@gmail.com](http://sophia.parafina@gmail.com)\>
> 
> Date: Sun, July 31, 2011 1:19 pm
> 
> To: elasticsearch \<[elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)\>
> 
> Sorry, I should have attached the error I get when I save the mapping
> 
> to a file and register it.
> 
> curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> 
> curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> 
> {"error":"ActionRequestValidationException[Validation Failed: 1:
> 
> mapping type is missing;]","status":500}
> 
> On Jul 31, 11:01 am, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com)\> wrote:
> 
> \> The mapping you gisted looks good, what is not working? Maybe you can gist a
> 
> \> sample of what does not work for you? ([http://www.elasticsearch.org/help](http://www.elasticsearch.org/help)).
> 
> \>
> 
> \>
> 
> \>
> 
> \>
> 
> \>
> 
> \>
> 
> \>
> 
> \> On Sun, Jul 31, 2011 at 6:48 PM, sophiap \<sophia.paraf...@gmail.com\> wrote:
> 
> \> \> Hmmm, I think I don't understand what is meant by type, judging from
> 
> \> \> you example. I meant something like this[https://gist.github.com/1116899](https://gist.github.com/1116899)
> 
> \>
> 
> \> \> On Jul 31, 9:58 am, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com)\> wrote:
> 
> \> \> \> You mean having several fields in the json of type geo\_point? Something
> 
> \> \> like
> 
> \> \> \> this:[https://gist.github.com/1116858?Ifnot](https://gist.github.com/1116858?Ifnot), then gist the sample json
> 
> \> \> you
> 
> \> \> \> want to map.
> 
> \>
> 
> \> \> \> On Sun, Jul 31, 2011 at 4:17 PM, sophiap \<sophia.paraf...@gmail.com\>
> 
> \> \> wrote:
> 
> \> \> \> \> Is there an example for mapping multiple geo\_point types under one
> 
> \> \> \> \> index. I've searched the group for examples but all of them are for
> 
> \> \> \> \> single types and those work, but I can't get the correct syntax for
> 
> \> \> \> \> multiple types.
> 
> \>
> 
> \> \> \> \> sophia

---

<div class="post-metadata">

**Author:** ![sophia\_parafina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sophia_parafina/32/3158_2.png) [@sophia\_parafina](https://discuss.elastic.co/u/sophia_parafina)\
**Post date:** [July 31, 2011, 4:54pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/7 "2011-07-31T16:54:40Z")

</div>

Yes, this works if you are mapping only one type. But if you have two types,  
you get this error:

curl -XPUT [http://localhost:9200/geo/zipcode/\_mapping](http://localhost:9200/geo/zipcode/_mapping) -d @map2.json

{"error":"MapperParsingException[Mapping must have the `type` as the root  
object]","status":400}

Is mapping two types possible with the REST API? Or do I do this via the  
java API or through tire?

On Sun, Jul 31, 2011 at 11:25 AM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:

> You're just missing the mapping type's name; your curl line should be:
> 
> curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json
> 
> Also, afaik, if you're sending a file with -d, you need to prepend the name  
> with @ thus
> 
> curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json
> 
> HTH,  
> JP
> 
> -------- Original Message --------  
> Subject: Re: Mapping for multiple types under one index  
> From: sophiap [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> Date: Sun, July 31, 2011 1:19 pm  
> To: elasticsearch [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> 
> Sorry, I should have attached the error I get when I save the mapping  
> to a file and register it.
> 
> curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> 
> curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> 
> {"error":"ActionRequestValidationException[Validation Failed: 1:  
> mapping type is missing;]","status":500}
> 
> On Jul 31, 11:01 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > The mapping you gisted looks good, what is not working? Maybe you can  
> > gist a  
> > sample of what does not work for you? ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)  
> > ).
> > 
> > On Sun, Jul 31, 2011 at 6:48 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > wrote:
> > 
> > > Hmmm, I think I don't understand what is meant by type, judging from  
> > > you example. I meant something like this  
> > > [gist:1116899 · GitHub](https://gist.github.com/1116899)
> > 
> > > On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > 
> > > > You mean having several fields in the json of type geo\_point?  
> > > > Something  
> > > > like  
> > > > this:[gist:1116858 · GitHub](https://gist.github.com/1116858?Ifnot), then gist the sample  
> > > > json  
> > > > you  
> > > > want to map.
> > 
> > > > On Sun, Jul 31, 2011 at 4:17 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Is there an example for mapping multiple geo\_point types under one  
> > > > > index. I've searched the group for examples but all of them are for  
> > > > > single types and those work, but I can't get the correct syntax for  
> > > > > multiple types.
> > 
> > > > > sophia

---

<div class="post-metadata">

**Author:** ![jp\_lorandi](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jp\_lorandi](https://discuss.elastic.co/u/jp_lorandi)\
**Post date:** [July 31, 2011, 5:00pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/8 "2011-07-31T17:00:00Z")

</div>

So you're trying to send 2 mappings on a single call?

> -------- Original Message --------
> 
> Subject: Re: Mapping for multiple types under one index
> 
> From: sophia parafina \<[sophia.parafina@gmail.com](http://sophia.parafina@gmail.com)\>
> 
> Date: Sun, July 31, 2011 1:54 pm
> 
> To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> 
> Yes, this works if you are mapping only one type. But if you have two types, you get this error:
> 
> curl -XPUT [http://localhost:9200/geo/zipcode/\_mapping](http://localhost:9200/geo/zipcode/_mapping) -d @map2.json
> 
> {"error":"MapperParsingException[Mapping must have the `type` as the root object]","status":400}
> 
> Is mapping two types possible with the REST API? Or do I do this via the java API or through tire?
> 
> On Sun, Jul 31, 2011 at 11:25 AM, \<[jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com)\> wrote:
> 
> > You're just missing the mapping type's name; your curl line should be:
> > 
> > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json
> > 
> > Also, afaik, if you're sending a file with -d, you need to prepend the name with @ thus
> > 
> > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json
> > 
> > HTH,JP
> > 
> > > -------- Original Message --------
> > > 
> > > Subject: Re: Mapping for multiple types under one index
> > > 
> > > From: sophiap \<[sophia.parafina@gmail.com](http://sophia.parafina@gmail.com)\>
> > > 
> > > Date: Sun, July 31, 2011 1:19 pm
> > > 
> > > To: elasticsearch \<[elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)\>
> > > 
> > > Sorry, I should have attached the error I get when I save the mapping
> > > 
> > > to a file and register it.
> > > 
> > > curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> > > 
> > > curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> > > 
> > > {"error":"ActionRequestValidationException[Validation Failed: 1:
> > > 
> > > mapping type is missing;]","status":500}
> > > 
> > > On Jul 31, 11:01 am, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com)\> wrote:
> > > 
> > > \> The mapping you gisted looks good, what is not working? Maybe you can gist a
> > > 
> > > \> sample of what does not work for you? ([http://www.elasticsearch.org/help](http://www.elasticsearch.org/help)).
> > > 
> > > \>
> > > 
> > > \>
> > > 
> > > \>
> > > 
> > > \>
> > > 
> > > \>
> > > 
> > > \>
> > > 
> > > \>
> > > 
> > > \> On Sun, Jul 31, 2011 at 6:48 PM, sophiap \<sophia.paraf...@gmail.com\> wrote:
> > > 
> > > \> \> Hmmm, I think I don't understand what is meant by type, judging from
> > > 
> > > \> \> you example. I meant something like this[https://gist.github.com/1116899](https://gist.github.com/1116899)
> > > 
> > > \>
> > > 
> > > \> \> On Jul 31, 9:58 am, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com)\> wrote:
> > > 
> > > \> \> \> You mean having several fields in the json of type geo\_point? Something
> > > 
> > > \> \> like
> > > 
> > > \> \> \> this:[https://gist.github.com/1116858?Ifnot](https://gist.github.com/1116858?Ifnot), then gist the sample json
> > > 
> > > \> \> you
> > > 
> > > \> \> \> want to map.
> > > 
> > > \>
> > > 
> > > \> \> \> On Sun, Jul 31, 2011 at 4:17 PM, sophiap \<sophia.paraf...@gmail.com\>
> > > 
> > > \> \> wrote:
> > > 
> > > \> \> \> \> Is there an example for mapping multiple geo\_point types under one
> > > 
> > > \> \> \> \> index. I've searched the group for examples but all of them are for
> > > 
> > > \> \> \> \> single types and those work, but I can't get the correct syntax for
> > > 
> > > \> \> \> \> multiple types.
> > > 
> > > \>
> > > 
> > > \> \> \> \> sophia

---

<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:** [July 31, 2011, 5:12pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/9 "2011-07-31T17:12:03Z")

</div>

The mapping definition needs to include the type as the top level object,  
for example: { "zipcode" : { .... } } for the zipcode type.

The Java API and the REST APIs have exactly the same capabilities.

On Sun, Jul 31, 2011 at 7:54 PM, sophia parafina  
[sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)wrote:

> Yes, this works if you are mapping only one type. But if you have two  
> types, you get this error:
> 
> curl -XPUT [http://localhost:9200/geo/zipcode/\_mapping](http://localhost:9200/geo/zipcode/_mapping) -d @map2.json
> 
> {"error":"MapperParsingException[Mapping must have the `type` as the root  
> object]","status":400}
> 
> Is mapping two types possible with the REST API? Or do I do this via the  
> java API or through tire?
> 
> On Sun, Jul 31, 2011 at 11:25 AM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:
> 
> > You're just missing the mapping type's name; your curl line should be:
> > 
> > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json
> > 
> > Also, afaik, if you're sending a file with -d, you need to prepend the  
> > name with @ thus
> > 
> > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json
> > 
> > HTH,  
> > JP
> > 
> > -------- Original Message --------  
> > Subject: Re: Mapping for multiple types under one index  
> > From: sophiap [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> > Date: Sun, July 31, 2011 1:19 pm  
> > To: elasticsearch [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> > 
> > Sorry, I should have attached the error I get when I save the mapping  
> > to a file and register it.
> > 
> > curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> > 
> > curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> > 
> > {"error":"ActionRequestValidationException[Validation Failed: 1:  
> > mapping type is missing;]","status":500}
> > 
> > On Jul 31, 11:01 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > The mapping you gisted looks good, what is not working? Maybe you can  
> > > gist a  
> > > sample of what does not work for you? (  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> > > 
> > > On Sun, Jul 31, 2011 at 6:48 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > > wrote:
> > > 
> > > > Hmmm, I think I don't understand what is meant by type, judging from  
> > > > you example. I meant something like this  
> > > > [gist:1116899 · GitHub](https://gist.github.com/1116899)
> > > 
> > > > On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > 
> > > > > You mean having several fields in the json of type geo\_point?  
> > > > > Something  
> > > > > like  
> > > > > this:[gist:1116858 · GitHub](https://gist.github.com/1116858?Ifnot), then gist the sample  
> > > > > json  
> > > > > you  
> > > > > want to map.
> > > 
> > > > > On Sun, Jul 31, 2011 at 4:17 PM, sophiap \<[sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)
> > > 
> > > > wrote:
> > > > 
> > > > > > Is there an example for mapping multiple geo\_point types under  
> > > > > > one  
> > > > > > index. I've searched the group for examples but all of them are  
> > > > > > for  
> > > > > > single types and those work, but I can't get the correct syntax  
> > > > > > for  
> > > > > > multiple types.
> > > 
> > > > > > sophia

---

<div class="post-metadata">

**Author:** ![sophia\_parafina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sophia_parafina/32/3158_2.png) [@sophia\_parafina](https://discuss.elastic.co/u/sophia_parafina)\
**Post date:** [July 31, 2011, 5:13pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/10 "2011-07-31T17:13:09Z")

</div>

On Sun, Jul 31, 2011 at 12:00 PM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:

> So you're trying to send 2 mappings on a single call?

Yes, to the same index.

When I sent the first geo\_point (place) mapping to the index and indexed the  
data, it works perfectly. I am able to search using a distance filter, etc.

I then sent a second geo\_point (zipcode) mapping to the same index and  
elasticsearch returned and OK. I then indexed the second set of data.  
However, when I use a distance filter, Elasticsearch returns no hits for  
the zipcode type, however querying on field works.

I would like to query one index by type with a distance filter.

> -------- Original Message --------  
> Subject: Re: Mapping for multiple types under one index  
> From: sophia parafina [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> Date: Sun, July 31, 2011 1:54 pm  
> To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> 
> Yes, this works if you are mapping only one type. But if you have two  
> types, you get this error:
> 
> curl -XPUT [http://localhost:9200/geo/zipcode/\_mapping](http://localhost:9200/geo/zipcode/_mapping) -d @map2.json
> 
> {"error":"MapperParsingException[Mapping must have the `type` as the root  
> object]","status":400}
> 
> Is mapping two types possible with the REST API? Or do I do this via the  
> java API or through tire?
> 
> On Sun, Jul 31, 2011 at 11:25 AM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:
> 
> > You're just missing the mapping type's name; your curl line should be:
> > 
> > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json
> > 
> > Also, afaik, if you're sending a file with -d, you need to prepend the  
> > name with @ thus
> > 
> > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json
> > 
> > HTH,  
> > JP
> > 
> > -------- Original Message --------  
> > Subject: Re: Mapping for multiple types under one index  
> > From: sophiap [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> > Date: Sun, July 31, 2011 1:19 pm  
> > To: elasticsearch [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> > 
> > Sorry, I should have attached the error I get when I save the mapping  
> > to a file and register it.
> > 
> > curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> > 
> > curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> > 
> > {"error":"ActionRequestValidationException[Validation Failed: 1:  
> > mapping type is missing;]","status":500}
> > 
> > On Jul 31, 11:01 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > The mapping you gisted looks good, what is not working? Maybe you can  
> > > gist a  
> > > sample of what does not work for you? (  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> > > 
> > > On Sun, Jul 31, 2011 at 6:48 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > > wrote:
> > > 
> > > > Hmmm, I think I don't understand what is meant by type, judging from  
> > > > you example. I meant something like this  
> > > > [gist:1116899 · GitHub](https://gist.github.com/1116899)
> > > 
> > > > On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > 
> > > > > You mean having several fields in the json of type geo\_point?  
> > > > > Something  
> > > > > like  
> > > > > this:[gist:1116858 · GitHub](https://gist.github.com/1116858?Ifnot), then gist the sample  
> > > > > json  
> > > > > you  
> > > > > want to map.
> > > 
> > > > > On Sun, Jul 31, 2011 at 4:17 PM, sophiap \<[sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)
> > > 
> > > > wrote:
> > > > 
> > > > > > Is there an example for mapping multiple geo\_point types under  
> > > > > > one  
> > > > > > index. I've searched the group for examples but all of them are  
> > > > > > for  
> > > > > > single types and those work, but I can't get the correct syntax  
> > > > > > for  
> > > > > > multiple types.
> > > 
> > > > > > sophia

---

<div class="post-metadata">

**Author:** ![jp\_lorandi](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jp\_lorandi](https://discuss.elastic.co/u/jp_lorandi)\
**Post date:** [July 31, 2011, 5:21pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/11 "2011-07-31T17:21:10Z")

</div>

You might want to PUT each mapping into ES via a separate cURL call. After that, index a record, then fetch the same mapping to verify that ES is using the mapping you specified and not guessing the type.

Finally, after all the above, if you could also gist the search whereby you're not getting results, that'd help lots.

> -------- Original Message --------
> 
> Subject: Re: Mapping for multiple types under one index
> 
> From: sophia parafina \<[sophia.parafina@gmail.com](http://sophia.parafina@gmail.com)\>
> 
> Date: Sun, July 31, 2011 2:13 pm
> 
> To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> 
> On Sun, Jul 31, 2011 at 12:00 PM, \<[jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com)\> wrote:
> 
> > So you're trying to send 2 mappings on a single call?
> 
> Yes, to the same index.
> 
> When I sent the first geo\_point (place) mapping to the index and indexed the data, it works perfectly. I am able to search using a distance filter, etc.
> 
> I then sent a second geo\_point (zipcode) mapping to the same index and elasticsearch returned and OK. I then indexed the second set of data. However, when I use a distance filter, Elasticsearch returns no hits for the zipcode type, however querying on field works.
> 
> I would like to query one index by type with a distance filter.
> 
> > > -------- Original Message --------
> > > 
> > > Subject: Re: Mapping for multiple types under one index
> > > 
> > > From: sophia parafina \<[sophia.parafina@gmail.com](http://sophia.parafina@gmail.com)\>
> > > 
> > > Date: Sun, July 31, 2011 1:54 pm
> > > 
> > > To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> > > 
> > > Yes, this works if you are mapping only one type. But if you have two types, you get this error:
> > > 
> > > curl -XPUT [http://localhost:9200/geo/zipcode/\_mapping](http://localhost:9200/geo/zipcode/_mapping) -d @map2.json
> > > 
> > > {"error":"MapperParsingException[Mapping must have the `type` as the root object]","status":400}
> > > 
> > > Is mapping two types possible with the REST API? Or do I do this via the java API or through tire?
> > > 
> > > On Sun, Jul 31, 2011 at 11:25 AM, \<[jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com)\> wrote:
> > > 
> > > > You're just missing the mapping type's name; your curl line should be:
> > > > 
> > > > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json
> > > > 
> > > > Also, afaik, if you're sending a file with -d, you need to prepend the name with @ thus
> > > > 
> > > > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json
> > > > 
> > > > HTH,JP
> > > > 
> > > > > -------- Original Message --------
> > > > > 
> > > > > Subject: Re: Mapping for multiple types under one index
> > > > > 
> > > > > From: sophiap \<[sophia.parafina@gmail.com](http://sophia.parafina@gmail.com)\>
> > > > > 
> > > > > Date: Sun, July 31, 2011 1:19 pm
> > > > > 
> > > > > To: elasticsearch \<[elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)\>
> > > > > 
> > > > > Sorry, I should have attached the error I get when I save the mapping
> > > > > 
> > > > > to a file and register it.
> > > > > 
> > > > > curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> > > > > 
> > > > > curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> > > > > 
> > > > > {"error":"ActionRequestValidationException[Validation Failed: 1:
> > > > > 
> > > > > mapping type is missing;]","status":500}
> > > > > 
> > > > > On Jul 31, 11:01 am, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com)\> wrote:
> > > > > 
> > > > > \> The mapping you gisted looks good, what is not working? Maybe you can gist a
> > > > > 
> > > > > \> sample of what does not work for you? ([http://www.elasticsearch.org/help](http://www.elasticsearch.org/help)).
> > > > > 
> > > > > \>
> > > > > 
> > > > > \>
> > > > > 
> > > > > \>
> > > > > 
> > > > > \>
> > > > > 
> > > > > \>
> > > > > 
> > > > > \>
> > > > > 
> > > > > \>
> > > > > 
> > > > > \> On Sun, Jul 31, 2011 at 6:48 PM, sophiap \<sophia.paraf...@gmail.com\> wrote:
> > > > > 
> > > > > \> \> Hmmm, I think I don't understand what is meant by type, judging from
> > > > > 
> > > > > \> \> you example. I meant something like this[https://gist.github.com/1116899](https://gist.github.com/1116899)
> > > > > 
> > > > > \>
> > > > > 
> > > > > \> \> On Jul 31, 9:58 am, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com)\> wrote:
> > > > > 
> > > > > \> \> \> You mean having several fields in the json of type geo\_point? Something
> > > > > 
> > > > > \> \> like
> > > > > 
> > > > > \> \> \> this:[https://gist.github.com/1116858?Ifnot](https://gist.github.com/1116858?Ifnot), then gist the sample json
> > > > > 
> > > > > \> \> you
> > > > > 
> > > > > \> \> \> want to map.
> > > > > 
> > > > > \>
> > > > > 
> > > > > \> \> \> On Sun, Jul 31, 2011 at 4:17 PM, sophiap \<sophia.paraf...@gmail.com\>
> > > > > 
> > > > > \> \> wrote:
> > > > > 
> > > > > \> \> \> \> Is there an example for mapping multiple geo\_point types under one
> > > > > 
> > > > > \> \> \> \> index. I've searched the group for examples but all of them are for
> > > > > 
> > > > > \> \> \> \> single types and those work, but I can't get the correct syntax for
> > > > > 
> > > > > \> \> \> \> multiple types.
> > > > > 
> > > > > \>
> > > > > 
> > > > > \> \> \> \> sophia

---

<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:** [July 31, 2011, 5:30pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/12 "2011-07-31T17:30:50Z")

</div>

I think I see what you are trying to do now, you set the two types for the  
mapping in the same put mapping request against a type. There is no put  
mapping API to put several mappings, you need to do it per type. Another  
option that you have is to provide the all mappings in the create index  
API:

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

.

On Sun, Jul 31, 2011 at 8:13 PM, sophia parafina  
[sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)wrote:

> On Sun, Jul 31, 2011 at 12:00 PM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:
> 
> > So you're trying to send 2 mappings on a single call?
> 
> Yes, to the same index.
> 
> When I sent the first geo\_point (place) mapping to the index and indexed  
> the data, it works perfectly. I am able to search using a distance filter,  
> etc.
> 
> I then sent a second geo\_point (zipcode) mapping to the same index and  
> elasticsearch returned and OK. I then indexed the second set of data.  
> However, when I use a distance filter, Elasticsearch returns no hits for  
> the zipcode type, however querying on field works.
> 
> I would like to query one index by type with a distance filter.
> 
> > -------- Original Message --------  
> > Subject: Re: Mapping for multiple types under one index  
> > From: sophia parafina [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> > Date: Sun, July 31, 2011 1:54 pm  
> > To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> > 
> > Yes, this works if you are mapping only one type. But if you have two  
> > types, you get this error:
> > 
> > curl -XPUT [http://localhost:9200/geo/zipcode/\_mapping](http://localhost:9200/geo/zipcode/_mapping) -d @map2.json
> > 
> > {"error":"MapperParsingException[Mapping must have the `type` as the root  
> > object]","status":400}
> > 
> > Is mapping two types possible with the REST API? Or do I do this via the  
> > java API or through tire?
> > 
> > On Sun, Jul 31, 2011 at 11:25 AM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:
> > 
> > > You're just missing the mapping type's name; your curl line should be:
> > > 
> > > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json
> > > 
> > > Also, afaik, if you're sending a file with -d, you need to prepend the  
> > > name with @ thus
> > > 
> > > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json
> > > 
> > > HTH,  
> > > JP
> > > 
> > > -------- Original Message --------  
> > > Subject: Re: Mapping for multiple types under one index  
> > > From: sophiap [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> > > Date: Sun, July 31, 2011 1:19 pm  
> > > To: elasticsearch [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> > > 
> > > Sorry, I should have attached the error I get when I save the mapping  
> > > to a file and register it.
> > > 
> > > curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> > > 
> > > curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> > > 
> > > {"error":"ActionRequestValidationException[Validation Failed: 1:  
> > > mapping type is missing;]","status":500}
> > > 
> > > On Jul 31, 11:01 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > 
> > > > The mapping you gisted looks good, what is not working? Maybe you can  
> > > > gist a  
> > > > sample of what does not work for you? (  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> > > > 
> > > > On Sun, Jul 31, 2011 at 6:48 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Hmmm, I think I don't understand what is meant by type, judging from  
> > > > > you example. I meant something like this  
> > > > > [gist:1116899 · GitHub](https://gist.github.com/1116899)
> > > > 
> > > > > On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > > 
> > > > > > You mean having several fields in the json of type geo\_point?  
> > > > > > Something  
> > > > > > like  
> > > > > > this:[gist:1116858 · GitHub](https://gist.github.com/1116858?Ifnot), then gist the sample  
> > > > > > json  
> > > > > > you  
> > > > > > want to map.
> > > > 
> > > > > > On Sun, Jul 31, 2011 at 4:17 PM, sophiap \<sophia.paraf...  
> > > > > > @gmail.com\>  
> > > > > > wrote:
> > > > > > 
> > > > > > > Is there an example for mapping multiple geo\_point types under  
> > > > > > > one  
> > > > > > > index. I've searched the group for examples but all of them are  
> > > > > > > for  
> > > > > > > single types and those work, but I can't get the correct syntax  
> > > > > > > for  
> > > > > > > multiple types.
> > > > 
> > > > > > > sophia

---

<div class="post-metadata">

**Author:** ![sophia\_parafina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sophia_parafina/32/3158_2.png) [@sophia\_parafina](https://discuss.elastic.co/u/sophia_parafina)\
**Post date:** [July 31, 2011, 6:07pm UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/13 "2011-07-31T18:07:11Z")

</div>

Thanks y'all. I walked through the process of setting the type mappings one  
by one and it works. Not sure what I was doing wrong, but here's the working  
process in gist: [Elasticsearch, register multiple geo\_point types to single index · GitHub](https://gist.github.com/1117013)

sophia

On Sun, Jul 31, 2011 at 12:30 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> I think I see what you are trying to do now, you set the two types for the  
> mapping in the same put mapping request against a type. There is no put  
> mapping API to put several mappings, you need to do it per type. Another  
> option that you have is to provide the all mappings in the create index  
> API:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html)  
> .
> 
> On Sun, Jul 31, 2011 at 8:13 PM, sophia parafina \<  
> [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)\> wrote:
> 
> > On Sun, Jul 31, 2011 at 12:00 PM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:
> > 
> > > So you're trying to send 2 mappings on a single call?
> > 
> > Yes, to the same index.
> > 
> > When I sent the first geo\_point (place) mapping to the index and indexed  
> > the data, it works perfectly. I am able to search using a distance filter,  
> > etc.
> > 
> > I then sent a second geo\_point (zipcode) mapping to the same index and  
> > elasticsearch returned and OK. I then indexed the second set of data.  
> > However, when I use a distance filter, Elasticsearch returns no hits for  
> > the zipcode type, however querying on field works.
> > 
> > I would like to query one index by type with a distance filter.
> > 
> > > -------- Original Message --------  
> > > Subject: Re: Mapping for multiple types under one index  
> > > From: sophia parafina [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> > > Date: Sun, July 31, 2011 1:54 pm  
> > > To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> > > 
> > > Yes, this works if you are mapping only one type. But if you have two  
> > > types, you get this error:
> > > 
> > > curl -XPUT [http://localhost:9200/geo/zipcode/\_mapping](http://localhost:9200/geo/zipcode/_mapping) -d @map2.json
> > > 
> > > {"error":"MapperParsingException[Mapping must have the `type` as the root  
> > > object]","status":400}
> > > 
> > > Is mapping two types possible with the REST API? Or do I do this via the  
> > > java API or through tire?
> > > 
> > > On Sun, Jul 31, 2011 at 11:25 AM, [jp.lorandi@cfyar.com](mailto:jp.lorandi@cfyar.com) wrote:
> > > 
> > > > You're just missing the mapping type's name; your curl line should be:
> > > > 
> > > > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d map2.json
> > > > 
> > > > Also, afaik, if you're sending a file with -d, you need to prepend the  
> > > > name with @ thus
> > > > 
> > > > curl -XPUT [http://localhost:9200/geo/MYTYPE/\_mapping](http://localhost:9200/geo/MYTYPE/_mapping) -d @map2.json
> > > > 
> > > > HTH,  
> > > > JP
> > > > 
> > > > -------- Original Message --------  
> > > > Subject: Re: Mapping for multiple types under one index  
> > > > From: sophiap [sophia.parafina@gmail.com](mailto:sophia.parafina@gmail.com)  
> > > > Date: Sun, July 31, 2011 1:19 pm  
> > > > To: elasticsearch [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)
> > > > 
> > > > Sorry, I should have attached the error I get when I save the mapping  
> > > > to a file and register it.
> > > > 
> > > > curl -XPUT '[http://localhost:9200/geo/](http://localhost:9200/geo/)'
> > > > 
> > > > curl -XPUT [http://localhost:9200/geo/\_mapping](http://localhost:9200/geo/_mapping) -d map2.json
> > > > 
> > > > {"error":"ActionRequestValidationException[Validation Failed: 1:  
> > > > mapping type is missing;]","status":500}
> > > > 
> > > > On Jul 31, 11:01 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > 
> > > > > The mapping you gisted looks good, what is not working? Maybe you can  
> > > > > gist a  
> > > > > sample of what does not work for you? (  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> > > > > 
> > > > > On Sun, Jul 31, 2011 at 6:48 PM, sophiap [sophia.paraf...@gmail.com](mailto:sophia.paraf...@gmail.com)  
> > > > > wrote:
> > > > > 
> > > > > > Hmmm, I think I don't understand what is meant by type, judging from  
> > > > > > you example. I meant something like this  
> > > > > > [gist:1116899 · GitHub](https://gist.github.com/1116899)
> > > > > 
> > > > > > On Jul 31, 9:58 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > > > > 
> > > > > > > You mean having several fields in the json of type geo\_point?  
> > > > > > > Something  
> > > > > > > like  
> > > > > > > this:[gist:1116858 · GitHub](https://gist.github.com/1116858?Ifnot), then gist the sample  
> > > > > > > json  
> > > > > > > you  
> > > > > > > want to map.
> > > > > 
> > > > > > > On Sun, Jul 31, 2011 at 4:17 PM, sophiap \<sophia.paraf...  
> > > > > > > @gmail.com\>  
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > Is there an example for mapping multiple geo\_point types under  
> > > > > > > > one  
> > > > > > > > index. I've searched the group for examples but all of them are  
> > > > > > > > for  
> > > > > > > > single types and those work, but I can't get the correct syntax  
> > > > > > > > for  
> > > > > > > > multiple types.
> > > > > 
> > > > > > > > sophia

---

<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:58am UTC](https://discuss.elastic.co/t/mapping-for-multiple-types-under-one-index/5006/14 "2017-07-06T03:58:45Z")

</div>


