Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the different between _id and _uid in elasticsearch?

Well, here is the detail:

First, I create three documents:

foo/bar/1
foo/bar/2
foo/bar/3

I want to get max id:

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
  host: 'localhost: 9200'
});

client.search({
  index: 'foo',
  type: 'bar',
  sort: '_id:desc',
  size: 1,
  fields: [ '_id' ]
}, function(err, resp) {
  if (err) return console.error(err);
  console.log(resp.hits); // _id is '1'
})

In the code above, I can not get right result.

Then, I google the reason about it, I found the '_uid'

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
  host: 'localhost: 9200'
});

client.search({
  index: 'foo',
  type: 'bar',
  sort: '_uid:desc', // here is a little bit different
  size: 1,
  fields: [ '_id' ]
}, function(err, resp) {
  if (err) return console.error(err);
  console.log(resp.hits); // _id is '3'
})

Yes I get the right result.

So question is

Can I say '_id' and '_uid' are the same things?

Is '_id' equal to '_uid'?

like image 307
jKey Avatar asked Nov 06 '25 02:11

jKey


1 Answers

Not exactly same .

The _uid field is automatically used when _type is not indexed to perform type based filtering, and does not require the _id to be indexed.

http://www.elastic.co/guide/en/elasticsearch/reference/1.3/mapping-uid-field.html

like image 94
Root Avatar answered Nov 08 '25 09:11

Root



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!