# Unique Constraint?

**URL:** <https://discuss.elastic.co/t/unique-constraint/11862>\
**Category:** Elasticsearch\
**Created:** [May 7, 2013, 7:21pm UTC](https://discuss.elastic.co/t/unique-constraint/11862 "2013-05-07T19:21:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ralph\_Trickey\_2](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Ralph\_Trickey\_2](https://discuss.elastic.co/u/Ralph_Trickey_2)\
**Post date:** [May 7, 2013, 7:21pm UTC](https://discuss.elastic.co/t/unique-constraint/11862/1 "2013-05-07T19:21:11Z")

</div>

I'm having problems understanding where I'm going wrong. I've set up a  
simple ES cluster and I am able to insert data fairly quickly using a  
simple program.

I would like to be able to define a unique constraint (ID Field) on the  
data and use it to remove remove any true duplicates which are duplicated  
across all fields. If I can use an ID column that I provide, I would be  
able to re-add a range of data knowing I had not created any duplicates.

It kind of sounded like the ID field does that, but it isn't clear from the  
documentation.

Following the ES web page suggestion, I added the following...  
[http://www.elasticsearch.org/guide/reference/mapping/id-field/](http://www.elasticsearch.org/guide/reference/mapping/id-field/)

When running the below script, I get an error about the provided ID not  
matching the content one.

What am I doing wrong?

curl -XPOST  
'[http://localhost:9200/log20130207/webservicebolcalls?replication=async](http://localhost:9200/log20130207/webservicebolcalls?replication=async)' -d  
'{  
"\_id": {  
"type": "string",  
"index": "not\_analyzed",  
"store" : "yes"  
}  
}  
'  
#log20130116

#curl -XPOST  
'[http://internal-cabinlb-279349935.us-east-1.elb.amazonaws.com:9200/log20130207/webservicebolcalls?replication=async?op\_type=create](http://internal-cabinlb-279349935.us-east-1.elb.amazonaws.com:9200/log20130207/webservicebolcalls?replication=async?op_type=create)'  
-d '{  
curl -XPOST  
'[http://localhost:9200/log20130207/webservicebolcalls?replication=async](http://localhost:9200/log20130207/webservicebolcalls?replication=async)' -d  
'{  
"\_timestamp":"1/16/2013 2:03:07 AM",  
"\_id":"2171985207026",  
"Milliseconds":"720",  
"MessageId":"e242134d-15b4-46e9-be88-61c96f97a797",  
"Direction":"Outbound",  
"Webid":"",  
"Token":"",  
"ErrorCode":"0",  
"MessageText":"|results|",  
"StackTrace":"",  
"Client":"10.3.44.1",  
"ClientId":"",  
"EmployeeId":""  
}  
'

#{"ok":true,"\_index":"log20130207","\_type":"webservicebolcalls","\_id":"UE6H-LrARnmqF\_JBC5LPkw","\_version":1}  
#{"error":"MapperParsingException[Failed to parse [\_id]]; nested:  
MapperParsingException[Provided id [TPGerHo3QLKz3jx1UXR09g] does not match  
the content one [2171985207026]]; ","status":400}

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [May 8, 2013, 11:05am UTC](https://discuss.elastic.co/t/unique-constraint/11862/2 "2013-05-08T11:05:15Z")

</div>

Hello Ralph,

The problem seems to be that the URI you're using is of the following  
format:

$HOST:$PORT/$INDEX/$TYPE

The other option is to have

$HOST:$PORT/$INDEX/$TYPE/$ID

When you index without ID in the URI, ES creates a random ID for you  
(TPGerHo3QLKz3jx1UXR09g in your case), which doesn't match the one you  
provide in the document (2171985207026). I would say the way to go is to  
skip providing the "\_id" field in the document (because ES takes it from  
the URI), and put it in the URI, like this:

curl -XPOST '  
[http://localhost:9200/log20130207/webservicebolcalls/2171985207026?op\_type=create-d](http://localhost:9200/log20130207/webservicebolcalls/2171985207026?op_type=create-d)  
'{  
"Milliseconds":"720",  
[...]  
}'

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Tue, May 7, 2013 at 10:21 PM, Ralph Trickey [ralphtrickey@gmail.com](mailto:ralphtrickey@gmail.com)wrote:

> I'm having problems understanding where I'm going wrong. I've set up a  
> simple ES cluster and I am able to insert data fairly quickly using a  
> simple program.
> 
> I would like to be able to define a unique constraint (ID Field) on the  
> data and use it to remove remove any true duplicates which are duplicated  
> across all fields. If I can use an ID column that I provide, I would be  
> able to re-add a range of data knowing I had not created any duplicates.
> 
> It kind of sounded like the ID field does that, but it isn't clear from  
> the documentation.
> 
> Following the ES web page suggestion, I added the following...  
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/mapping/id-field/)
> 
> When running the below script, I get an error about the provided ID not  
> matching the content one.
> 
> What am I doing wrong?
> 
> curl -XPOST '  
> [http://localhost:9200/log20130207/webservicebolcalls?replication=async](http://localhost:9200/log20130207/webservicebolcalls?replication=async)'  
> -d '{  
> "\_id": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "store" : "yes"  
> }  
> }  
> '  
> #log20130116
> 
> #curl -XPOST '  
> [http://internal-cabinlb-279349935.us-east-1.elb.amazonaws.com:9200/log20130207/webservicebolcalls?replication=async?op\_type=create](http://internal-cabinlb-279349935.us-east-1.elb.amazonaws.com:9200/log20130207/webservicebolcalls?replication=async?op_type=create)'  
> -d '{  
> curl -XPOST '  
> [http://localhost:9200/log20130207/webservicebolcalls?replication=async](http://localhost:9200/log20130207/webservicebolcalls?replication=async)'  
> -d '{  
> "\_timestamp":"1/16/2013 2:03:07 AM",  
> "\_id":"2171985207026",  
> "Milliseconds":"720",  
> "MessageId":"e242134d-15b4-46e9-be88-61c96f97a797",  
> "Direction":"Outbound",  
> "Webid":"",  
> "Token":"",  
> "ErrorCode":"0",  
> "MessageText":"|results|",  
> "StackTrace":"",  
> "Client":"10.3.44.1",  
> "ClientId":"",  
> "EmployeeId":""  
> }  
> '
> 
> #{"ok":true,"\_index":"log20130207","\_type":"webservicebolcalls","\_id":"UE6H-LrARnmqF\_JBC5LPkw","\_version":1}  
> #{"error":"MapperParsingException[Failed to parse [\_id]]; nested:  
> MapperParsingException[Provided id [TPGerHo3QLKz3jx1UXR09g] does not match  
> the content one [2171985207026]]; ","status":400}
> 
> --  
> 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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ralph\_Trickey\_2](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Ralph\_Trickey\_2](https://discuss.elastic.co/u/Ralph_Trickey_2)\
**Post date:** [May 8, 2013, 4:07pm UTC](https://discuss.elastic.co/t/unique-constraint/11862/3 "2013-05-08T16:07:43Z")

</div>

Thanks Radu, I'll give that a try.

> 

--  
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).  
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:37am UTC](https://discuss.elastic.co/t/unique-constraint/11862/4 "2017-07-06T02:37:35Z")

</div>


