0

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

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 中使用类似的东西吗?

4

1 回答 1

3

我相信一旦你插入记录,你就会得到这种形式的 json 响应:

{"ok":true,"_index":"you index name","_type":"you type name","_id":"插入文档的id","_version":1}

所以在你的情况下pid._id是你正在寻找的

于 2013-11-01T17:00:45.053 回答