Elasticsearch与Linux(第七天)-查找数据

一.MultiGet

特点:只能查询文档

1.批量导出文档

GET /_mget
{
  "docs":[
    {
      "_index": "lib",
      "_type": "user",
      "_id": 1
    },
     {
      "_index": "lib",
      "_type": "user",
      "_id": 2
    },
     {
      "_index": "lib",
      "_type": "user",
      "_id": 3
    }
    ]
}

Elasticsearch与Linux(第七天)-查找数据_第1张图片

2.也可以具体指定字段

GET /_mget
{
  "docs":[
    {
      "_index": "lib",
      "_type": "usr",
      "_id": 1,
      "_source": "interests"
    }

    ]
}

3.简化写法

GET /lib/usr/_mget
{
  "docs":[
    {
      "_id": 1,
      "_source": "interests"
    }
    ]
}
GET /lib/usr/_mget
{
  "ids":["1","2"]
}

二.BUIK API

特点:能操作文档,写到内存里,但文档量有限制

1.批量添加

POST /lib2/usr/_bulk
{"index":{"_id":1}}
{"title":"JAVA","price":33}
{"index":{"_id":2}}
{"title":"C","price":44}
{"index":{"_id":3}}
{"title":"Python","price":55}

2.批量创建

POST /_bulk
{"create":{"_index":"tt","_type":"ttt","_id":"100"}}
{"name":"list1"}
{"index":{"_index":"tt","_type":"ttt"}}
{"name":"list2"}

3.批量查询

GET /lib/usr/_mget
{
  "ids":["1","2"]
}

4.批量删除

POST /lib2/usr/_bulk
{"delete":{"_index":"lib2","_type":"usr","_id":3}}

5.批量更新

POST /_bulk
{"update":{"_index":"lib2","_type":"usr","_id":"2"}}
{"doc":{"price":50}}

6.查找

# 字符串会分词
GET /lib2/usr/_search?q=title:JAVA
GET /lib2/usr/_search?q=title:JAVA-1

你可能感兴趣的:(elasticsearch)