# Using existing field for mapping

**URL:** https://discuss.elastic.co/t/using-existing-field-for-mapping/19051
**Category:** Elasticsearch
**Created:** [August 3, 2014, 8:14am UTC](https://discuss.elastic.co/t/using-existing-field-for-mapping/19051 "2014-08-03T08:14:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ayush](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Ayush](https://discuss.elastic.co/u/Ayush)
#### Post date: [August 3, 2014, 8:14am UTC](https://discuss.elastic.co/t/using-existing-field-for-mapping/19051/1 "2014-08-03T08:14:59Z")

</div>

I am new to elastic search, I have created an index "cmn" with a type  
"mention". I am trying to import data from my existing solr to  
elasticsearch, so I want to map an existing field to the \_id field.

I have created the following file under /config/mappings/cmn/,

```
{
    "mappings": {
"mentions":{

```

"\_id" : {  
"path" : "docKey"  
}  
}  
}  
}

But this doesn't seem to be working, every time I index a record the  
following \_id is created,

```
        "_index": "cmn",
        "_type": "mentions",
        "_id": "k4E0dJr6Re2Z39HAIjYMmg",
        "_score": 1

```

Also, the mapping is not reflects. I have also tried the following option,

```
{
    "mappings": {

```

"\_id" : {  
"path" : "docKey"  
}  
}  
}

SAMPLE DOCUMENT: Basically a tweet.

```
 {
           "usrCreatedDate": "2012-01-24 21:34:47",
           "sex": "U",
           "listedCnt": 2,
           "follCnt": 432,
           "state": "Southampton",
           "classified": 0,
           "favCnt": 468,
           "timeZone": "Casablanca",
           "twitterId": 473333038,
           "lang": "en",
           "stnostem": "#ootd #ootw #fashion #styling #photography 

```

#white #pink #playsuit #prada #sunny #spring http://t.co/YbPFrXlpuh",  
"sourceId": "tw",  
"timestamp": "2014-04-09T22:58:00.396Z",  
"sentiment": 0,  
"updatedOnGMTDate": "2014-04-09T22:56:57.000Z",  
"userLocation": "Southampton",  
"age": 0,  
"priorityScore": 57.4700012207031,  
"statusCnt": 14612,  
"name": "YazzyK",  
"profilePicUrl":  
"http://pbs.twimg.com/profile\_images/453578494556270594/orsA0pKi\_normal.jpeg",  
"mentions": "",  
"sourceStripped": "Instagram",  
"collectionName": "STREAMING",  
"tags": "557/161/193/197",  
"msgid": 1397084280396.33,  
"_version_": 1464949081784713200,  
"url2":  
"{"urls":[{"url":"http://t.co/YbPFrXlpuh","expandedURL":"http://instagram.com/p/mliZbgxVZm/","displayURL":"instagram.com/p/mliZbgxVZm/","start":88,"end":110}]}",  
"links": "http://t.co/YbPFrXlpuh",  
"retweetedStatus": "",  
"twtScreenName": "YazKader",  
"postId": "454030232501358592",  
"country": "Bermuda",  
"message": "#ootd #ootw #fashion #styling #photography  
#white #pink #playsuit #prada #sunny #spring http://t.co/YbPFrXlpuh",  
"source": "\<a href="http://instagram.com"  
rel="nofollow"\>Instagram",  
"parentStatusId": -1,  
"bio": "Live and breathe Fashion. Persian and proud-  
Instagram: @Yazkader",  
"createdOnGMTDate": "2014-04-09T22:56:57.000Z",  
"searchText": "#ootd #ootw #fashion #styling #photography  
#white #pink #playsuit #prada #sunny #spring [http://t.co/YbPFrXlpuh](http://t.co/YbPFrXlpuh)",  
"isFavorited": "False",  
"frenCnt": 214,  
"docKey": "tw\_454030232501358592"  
}  
Also, how can we create unique mapping for each "TYPE" and not just the  
index.

Thanks

--  
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/15c33940-d95c-48b4-afcd-a3cccdabafaf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/15c33940-d95c-48b4-afcd-a3cccdabafaf%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)
#### Post date: [August 4, 2014, 8:05am UTC](https://discuss.elastic.co/t/using-existing-field-for-mapping/19051/2 "2014-08-04T08:05:00Z")

</div>

What API are you using to communicate with ES ?

03 август 2014, неделя, 11:14:59 UTC+3, Ayush написа:

> I am new to Elasticsearch, I have created an index "cmn" with a type  
> "mention". I am trying to import data from my existing solr to  
> elasticsearch, so I want to map an existing field to the \_id field.
> 
> I have created the following file under /config/mappings/cmn/,
> 
> ```
> {
> "mappings": {
> "mentions":{
> 
> ```
> 
> "\_id" : {  
> "path" : "docKey"  
> }  
> }  
> }  
> }
> 
> But this doesn't seem to be working, every time I index a record the  
> following \_id is created,
> 
> ```
> "_index": "cmn",
> "_type": "mentions",
> "_id": "k4E0dJr6Re2Z39HAIjYMmg",
> "_score": 1
> 
> ```
> 
> Also, the mapping is not reflects. I have also tried the following option,
> 
> ```
> {
> "mappings": {
> 
> ```
> 
> "\_id" : {  
> "path" : "docKey"  
> }  
> }  
> }
> 
> SAMPLE DOCUMENT: Basically a tweet.
> 
> ```
> {
> "usrCreatedDate": "2012-01-24 21:34:47",
> "sex": "U",
> "listedCnt": 2,
> "follCnt": 432,
> "state": "Southampton",
> "classified": 0,
> "favCnt": 468,
> "timeZone": "Casablanca",
> "twitterId": 473333038,
> "lang": "en",
> "stnostem": "#ootd #ootw #fashion #styling #photography 
> 
> ```
> 
> #white #pink #playsuit #prada #sunny #spring [http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> "sourceId": "tw",  
> "timestamp": "2014-04-09T22:58:00.396Z",  
> "sentiment": 0,  
> "updatedOnGMTDate": "2014-04-09T22:56:57.000Z",  
> "userLocation": "Southampton",  
> "age": 0,  
> "priorityScore": 57.4700012207031,  
> "statusCnt": 14612,  
> "name": "YazzyK",  
> "profilePicUrl": "  
> [http://pbs.twimg.com/profile\_images/453578494556270594/orsA0pKi\_normal.jpeg](http://pbs.twimg.com/profile_images/453578494556270594/orsA0pKi_normal.jpeg)  
> ",  
> "mentions": "",  
> "sourceStripped": "Instagram",  
> "collectionName": "STREAMING",  
> "tags": "557/161/193/197",  
> "msgid": 1397084280396.33,  
> "_version_": 1464949081784713200,  
> "url2": "{"urls":[{"url":"[http://t.co/YbPFrXlpuh\](http://t.co/YbPFrXlpuh%5C)  
> ","expandedURL":"[http://instagram.com/p/mliZbgxVZm/\",\"displayURL\":\"](http://instagram.com/p/mliZbgxVZm/%5C%22,%5C%22displayURL%5C%22:%5C%22)  
> instagram.com/p/mliZbgxVZm/\ [http://instagram.com/p/mliZbgxVZm/\](http://instagram.com/p/mliZbgxVZm/%5C)  
> ","start":88,"end":110}]}",  
> "links": "[http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> "retweetedStatus": "",  
> "twtScreenName": "YazKader",  
> "postId": "454030232501358592",  
> "country": "Bermuda",  
> "message": "#ootd #ootw #fashion #styling #photography  
> #white #pink #playsuit #prada #sunny #spring [http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> "source": "\<a href="[http://instagram.com](http://instagram.com)"  
> rel="nofollow"\>Instagram",  
> "parentStatusId": -1,  
> "bio": "Live and breathe Fashion. Persian and proud-  
> Instagram: @Yazkader",  
> "createdOnGMTDate": "2014-04-09T22:56:57.000Z",  
> "searchText": "#ootd #ootw #fashion #styling #photography  
> #white #pink #playsuit #prada #sunny #spring [http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> "isFavorited": "False",  
> "frenCnt": 214,  
> "docKey": "tw\_454030232501358592"  
> }  
> Also, how can we create unique mapping for each "TYPE" and not just the  
> index.
> 
> Thanks

--  
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/9f442b15-f956-4829-8436-c4ab10fd429e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9f442b15-f956-4829-8436-c4ab10fd429e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Ayush](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Ayush](https://discuss.elastic.co/u/Ayush)
#### Post date: [August 5, 2014, 10:02am UTC](https://discuss.elastic.co/t/using-existing-field-for-mapping/19051/3 "2014-08-05T10:02:40Z")

</div>

I am using Java API, but have tried doing this using,

1. putting a mapping file in /config/mapping etc.
2. Using curl

On Monday, August 4, 2014 1:35:00 PM UTC+5:30, Tihomir Lichev wrote:

> What API are you using to communicate with ES ?
> 
> 03 август 2014, неделя, 11:14:59 UTC+3, Ayush написа:
> 
> > I am new to Elasticsearch, I have created an index "cmn" with a type  
> > "mention". I am trying to import data from my existing solr to  
> > elasticsearch, so I want to map an existing field to the \_id field.
> > 
> > I have created the following file under /config/mappings/cmn/,
> > 
> > ```
> > {
> > "mappings": {
> > "mentions":{
> > 
> > ```
> > 
> > "\_id" : {  
> > "path" : "docKey"  
> > }  
> > }  
> > }  
> > }
> > 
> > But this doesn't seem to be working, every time I index a record the  
> > following \_id is created,
> > 
> > ```
> > "_index": "cmn",
> > "_type": "mentions",
> > "_id": "k4E0dJr6Re2Z39HAIjYMmg",
> > "_score": 1
> > 
> > ```
> > 
> > Also, the mapping is not reflects. I have also tried the following option,
> > 
> > ```
> > {
> > "mappings": {
> > 
> > ```
> > 
> > "\_id" : {  
> > "path" : "docKey"  
> > }  
> > }  
> > }
> > 
> > SAMPLE DOCUMENT: Basically a tweet.
> > 
> > ```
> > {
> > "usrCreatedDate": "2012-01-24 21:34:47",
> > "sex": "U",
> > "listedCnt": 2,
> > "follCnt": 432,
> > "state": "Southampton",
> > "classified": 0,
> > "favCnt": 468,
> > "timeZone": "Casablanca",
> > "twitterId": 473333038,
> > "lang": "en",
> > "stnostem": "#ootd #ootw #fashion #styling #photography 
> > 
> > ```
> > 
> > #white #pink #playsuit #prada #sunny #spring [http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> > "sourceId": "tw",  
> > "timestamp": "2014-04-09T22:58:00.396Z",  
> > "sentiment": 0,  
> > "updatedOnGMTDate": "2014-04-09T22:56:57.000Z",  
> > "userLocation": "Southampton",  
> > "age": 0,  
> > "priorityScore": 57.4700012207031,  
> > "statusCnt": 14612,  
> > "name": "YazzyK",  
> > "profilePicUrl": "  
> > [http://pbs.twimg.com/profile\_images/453578494556270594/orsA0pKi\_normal.jpeg](http://pbs.twimg.com/profile_images/453578494556270594/orsA0pKi_normal.jpeg)  
> > ",  
> > "mentions": "",  
> > "sourceStripped": "Instagram",  
> > "collectionName": "STREAMING",  
> > "tags": "557/161/193/197",  
> > "msgid": 1397084280396.33,  
> > "_version_": 1464949081784713200,  
> > "url2": "{"urls":[{"url":"[http://t.co/YbPFrXlpuh\](http://t.co/YbPFrXlpuh%5C)  
> > ","expandedURL":"[http://instagram.com/p/mliZbgxVZm/\](http://instagram.com/p/mliZbgxVZm/%5C)  
> > ","displayURL":"instagram.com/p/mliZbgxVZm/\   
> > [http://instagram.com/p/mliZbgxVZm/\](http://instagram.com/p/mliZbgxVZm/%5C)","start":88,"end":110}]}",  
> > "links": "[http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> > "retweetedStatus": "",  
> > "twtScreenName": "YazKader",  
> > "postId": "454030232501358592",  
> > "country": "Bermuda",  
> > "message": "#ootd #ootw #fashion #styling #photography  
> > #white #pink #playsuit #prada #sunny #spring [http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> > "source": "\<a href="[http://instagram.com](http://instagram.com)"  
> > rel="nofollow"\>Instagram",  
> > "parentStatusId": -1,  
> > "bio": "Live and breathe Fashion. Persian and proud-  
> > Instagram: @Yazkader",  
> > "createdOnGMTDate": "2014-04-09T22:56:57.000Z",  
> > "searchText": "#ootd #ootw #fashion #styling #photography  
> > #white #pink #playsuit #prada #sunny #spring [http://instagram.com/p/mliZbgxVZm/](http://t.co/YbPFrXlpuh)",  
> > "isFavorited": "False",  
> > "frenCnt": 214,  
> > "docKey": "tw\_454030232501358592"  
> > }  
> > Also, how can we create unique mapping for each "TYPE" and not just the  
> > index.
> > 
> > Thanks

--  
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/aaa67013-17d7-4c25-a697-65b7cbc4240d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/aaa67013-17d7-4c25-a697-65b7cbc4240d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)
#### Post date: [August 5, 2014, 11:46am UTC](https://discuss.elastic.co/t/using-existing-field-for-mapping/19051/4 "2014-08-05T11:46:15Z")

</div>

1. Try go execute GET [http://yourhost:9200/\_mapping](http://yourhost:9200/_mapping) and check if the  
mapping mentions is properly created with correct \_id path
2. When indexing the documents you can construct your index request this  
way:

IndexRequestBuilder indexRequestBuilder = getClient().prepareIndex(index,  
type).setSource(data);

where data is your Map or JSON you want to index

I tested with curl (-XPUT for mapping and -XPOST for indexing ! ) and seems  
like it works 🙂  
I'm also using \_id path and Java API in my own project and have no problems  
with it so far

--  
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/d8e367d3-e6f7-4b54-9f3a-30154eb66a69%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d8e367d3-e6f7-4b54-9f3a-30154eb66a69%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:10am UTC](https://discuss.elastic.co/t/using-existing-field-for-mapping/19051/5 "2017-07-06T01:10:46Z")

</div>


