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'?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With