------Create 增
POST /索引/类型/ID
{
//参数
}
curl -XPOST 'http://hdp-1:9200/search2/article2/1' -H 'Content-Type: application/json' -d '{
"title": "Test1",
"tags" : "test",
"summary" : "test",
"content" : "test1 content",
"pubtime":"0"
}'
curl -XPOST 'http://hdp-1:9200/search2/article2/2' -H 'Content-Type: application/json' -d '{
"title": "Test2",
"tags" : "test2",
"summary" : "test2",
"content" : "test2 content2",
"pubtime":"2"
}'
返回结果
{"_index":"search2","_type":"article2","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
------Update 修改
POST /索引/类型/ID
{
//参数
}
curl -XPOST 'http://hdp-1:9200/search2/article2/1' -H 'Content-Type: application/json' -d '{
"title": "Test1(updated)",
"tags" : "test",
"summary" : "test",
"content" : "test1 content",
"pubtime":"0"
}'
{"_index":"search2","_type":"article2","_id":"99","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1}
------Query 查询
-----根据ID查询
GET /索引/类型/ID
curl -XGET 'http://hdp-1:9200/search2/article2/1'
结果:
{"_index":"search2","_type":"article2","_id":"99","_version":2,"found":true,"_source":{
"title": "Test1(updated)",
"tags" : "test",
"summary" : "test",
"content" : "test1 content",
"pubtime":"0"
}}
--- 查询所有
curl -XGET 'http://hdp-1:9200/search2/article2/_search' -H 'Content-Type: application/json' -d '{
"query" : {
"match_all" : { }
}
}'
--- 复杂查询
curl -XGET 'http://hdp-1:9200/search/article/_search' -H 'Content-Type: application/json' -d '{
"query": {
"bool": {
"must": [
{ "match": { "title": "标题"}},
{ "match": { "tags": "标签" }}
],
"filter": [
{ "range": { "pubtime": { "gte": "1000" }}}
]
}
}
}'
注:最好用英文,汉字有时找不到
----删除
DELETE /索引/类型/ID
curl -XDELETE 'http://hdp-1:9200/search2/article2/1'
使用Kibana进行交互操作
GET /student/banji/1
GET /student/banji/1?_source=title
GET /student/banji/_search
{
"query" : {
"bool" : {
"filter" : {
"term" : {
"status" : "ok"
}
}
}
}
}
GET _search
{
"query": {
"match_all": {}
}
}
GET search/article/_search
{
"query": {
"match_all": {}
}
}
GET search/article/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "标题"}},
{ "match": { "tags": "标签" }}
],
"filter": [
{ "range": { "pubtime": { "gte": "1000" }}}
]
}
}
}
GET search/article/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "标题"}},
{ "match": { "tags": "标签" }}
]
}
}
}
GET search/article/_search
{
"query": {
"bool": {
"filter": [
{ "range": { "pubtime": { "gte": "60" }}}
]
}
}
}
GET search/article/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "标题"}},
{ "match": { "tags": "标签" }}
],
"filter": [
{ "range": { "pubtime": { "gt": "60" }}}
]
}
}
}
GET search/article/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "标题"}},
{ "match": { "tags": "标签" }}
],
"filter": [
{ "range": { "pubtime": { "gte": "60" }}}
]
}
}
}
POST search/article/3
{
"title": "标题3",
"tags" : "标签3",
"content" : "内容3",
"author" : "作者3",
"pubtime":10000
}
POST search/article/2
{
"title": "标题2",
"tags" : "标签2",
"content" : "内容2",
"author" : "作者2",
"pubtime":100
}
POST student/banji/3
{
"title":"3班",
"num":"55",
"status":"ok"
}
PUT /ecommerce/product/1
{
"name" : "gaolujie yagao",
"desc" : "gaoxiao meibai",
"price" : 30,
"producer" : "gaolujie producer",
"tags": [ "meibai", "fangzhu" ]
}
GET /student