gpt4 book ai didi

jquery - 使用jQuery将数据插入Elasticsearch并获取最后插入的文档的ID

转载 作者:行者123 更新时间:2023-12-03 00:43:37 25 4
gpt4 key购买 nike

使用以下代码,将数据插入到我的elasticsearch索引中:

var personendaten = { 
"vorname": $.trim( $( '#vorname' ).val() ),
"nachname": $.trim( $( '#nachname' ).val() )
};

$.ajax({
type: "POST",
url: 'http://localhost:9200/castingdb/personen',
dataType: 'json',
data: JSON.stringify( personendaten ),
success: function( pid ){
window.location = '?seite=personen&sub=profil&id='+pid;
}
});

在我的成功函数中,我需要来自elasticsearch的返回值,该值可为我提供插入文档的ID。
在PHP和MySQL中,有last_insert_id函数,我可以在jQuery和elasticsearch中使用类似的东西吗?

最佳答案

我相信一旦您插入记录,您将获得以下形式的json响应:

{"ok":true,"_index":"you index name","_type":"you type name","_id":"id of inserted document","_version":1}



所以在您的情况下 pid._id是您要寻找的

关于jquery - 使用jQuery将数据插入Elasticsearch并获取最后插入的文档的ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19730019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com