简体   繁体   English

如何在弹性搜索中为字段创建自动增量值

[英]How do I create auto increment value for a field in elastic search

I'm setting up an API for reading employee details, How can I se index ID and employee id as auto-increment 我正在设置一个用于读取员工详细信息的API,如何将索引ID和员工ID设置为自动递增

I'm using express4.17 and elasticsearch7.3 我正在使用express4.17和elasticsearch7.3

const client  = require('../client/esConnect')
module.exports.createAttendance = async (body) => {
    try{
        let payload  = payloadValue(body);
        let response = await client.index(payload);
        return response;
    }catch(error){
        console.log(error);
        throw error;
    }

}
payloadValue = (body) => {
    return payload = {
        index: "attendance",
        type: "_doc",
        id: 4,
        body: {
            empid: body.empid,
            date: body.date,
            present: body.present
        }
    }
}

As far as I can remember, Elasticsearch does not support (anymore) this kind of auto-increment ID. 据我所记得,Elasticsearch不支持(不再)这种自动增量ID。 The ID field is automatically generated as a hash. ID字段自动生成为哈希。

However, if you need to store somehow that number, you can add them within your code as another field or just overwriting the ID field. 但是,如果您需要以某种方式存储该数字,则可以将它们添加到代码中作为另一个字段,或者仅覆盖ID字段。

Remember that Elasticsearch is NOT intended to be used as a Structured / ER database (like SQL). 请记住,Elasticsearch不能用作结构化/ ER数据库(如SQL)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM