Elasticsearch提供近乎实时的数据操作和搜索功能。默认情况下,您可以从 index/update/delete 数据的时间延迟一秒钟的延迟(刷新间隔),直到它在搜索结果中出现的时间。这是它与其他平台(如SQL)的重要区别,其中数据在事务完成后立即可用。
Index/Update
我们需要更新文档,首先添加一个文档
PUT /customer/external/1?pretty
{
"name": "John Doe"
}
然后对该文档进行更新
PUT /customer/external/1?pretty
{
"name": "Jane Doe"
}
然后进行查看
GET /customer/external/1?pretty
发现其已经被修改
若我们使用不同的id添加数据时,则会添加新的文档2
PUT /customer/external/2?pretty
{
"name": "Jane Doe"
}
在put时id是必须的,
但是在用post添加数据时id是可选的,添加一条数据不指定id,系统会自动生成一个id给予它
POST /customer/external?pretty
{
"name": "Jane Doe"
}
也可指定id进行添加数据
POST /customer/external/1?pretty
{
"name": "Jane Doe"
}