# 查看指定index、type和id的文档,返回结构如下,found字段表示是否找到对应的文档
curl -XGET http://localhost:9200/_index/_type/_id?pretty
# 返回
{
"_index": "_index",
"_type": "_type",
"_id": "_id",
"_version": 1,
"found": true,
"_source": {}
}
# 查看指定index、type和id的文档的对应字段,返回结构如下,found字段表示是否找到对应的文档
curl -XGET http://localhost:9200/_index/_type/_id?_source=title
# 返回
{
"_index": "_index",
"_type": "_type",
"_id": "_id",
"_version": 1,
"found": true,
"_source": {
"title": "0735ee78-8bd9-59ef-9031-1fd1c647a0a5"
}
}
# 查看指定index、type和id的文档的_source而不查看其他字段,返回结构如下
curl -XGET http://localhost:9200/_index/_type/_id/_source
# 返回结构
{
"title": "0735ee78-8bd9-59ef-9031-1fd1c647a0a5"
}
# 查看指定index、type和id的文档是否存在
curl -i -XHEAD http://localhost:9200/_index/_type/_id/_source
# 如果存在则返回如下结构
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 903
# 不存在返回如下格式
HTTP/1.1 404 Not Found
content-type: application/json; charset=UTF-8
content-length: 98
# 删除文档
curl -XDELETE http://localhost:9200/_index/_type/_id
# 更新文档
curl -XPOST 127.0.0.1:9200/_index/_type/_id/_update -d '{"doc":{"event_type":"005"}}'
或
curl -XPOST 127.0.0.1:9200/_index/_type/_id/_update -d '{"script":"ctx._source.event_type=006"}'
# 增加文档
curl -XPUT 127.0.0.1/_index/_type/_id -d '{"title": "My first blog entry","text": "Just trying this out...","date": "2014/01/01"}'
如果不指定ID,ID为默认的UUID
# 查询索引
curl -XGET 127.0.0.1:9200/_index/_search
返回前十条数据
# 分页查询
curl -XGET 127.0.0.1:9200/_index/_search?size=5&from=5
返回前5到第十条数据
size : 结果数,默认 10
from : 跳过开始的结果数,默认 0
# 查看mapping
curl -XGET 127.0.0.1:9200/_index/_mapping/(_type)
小括号括起来的表示可选
# query查询
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{}}'
# 空查询 等同于
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"match_all":{}}}'
# 过滤
# 查询特定匹配
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"match":{}}}'
# bool过滤
# must :: 多个查询条件的完全匹配,相当于 and 。
# must_not :: 多个查询条件的相反匹配,相当于 not 。
# should :: 至少有一个查询条件匹配, 相当于 or 。
# 但是当should和must共用时should不生效
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"bool":{"must":{"match":{}}}}}'
#multi_match 允许你做 match 查询的基础上同时搜索多个字段:
curl -XPOST 127.0.0.1:9200/_index/_search-d '{"query":{"multi_match":{"query":"","fields":[""]}}}'
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"bool":{"must_not":{"match":{}}}}}'
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"bool":{"shold":{"match":{}}}}}'
#term过滤
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"term":{"tag":"1"}}}'
#terms允许查询多个
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"terms":{"tag":["1","2"]}}}'
#range 过滤 gt:大于 gte:大于等于 lt:小于 lte:小于等于
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"range":{"age":{"gte":20,"lt":30}}}}'
#exists 过滤字段是否存在,key为field,value为字段名
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"exists":{"field":"tag"}}}'
curl -XPOST 127.0.0.1:9200/_index/_search -d '{"query":{"missing":{"field":"tag"}}}'