URL查询
索引查询
创建索引库 curl -XPUT master:9200/bigdata
查看索引信息 curl -XGET master:9200/bigdata ==>获取当前索引库的配置信息
查询所有的索引 curl ‘http://master:9200/_cat/indices?v‘
GET _cat/indices?v
判断索引是否存在 HEAD 索引名称
删除索引 DELETE 索引名
文档查询
创建文档
curl -XPOST master:9200/bigdata/product/1 -d ‘{“name”:”hadoop”, “author”:”Doug Couting”, “lastest_version”:”3.0.0”}’
查询文档信息
curl -XGET master:9200/bigdata/_search ==>查询索引库下面的所有索引信息
curl -XGET master:9200/bigdata/_search?pretty==>对查询结果格式化
curl -XGET master:9200/bigdata/type/1?pretty==>精确查询索引id为1的一条信息
//查指定的字段值
curl ‘localhost:9200/power_json/_search?pretty&q=TESTID:10000000107326732674’
//查指定的字段值,并只显示3个
curl ‘localhost:9200/power_json/_search?pretty&q=TESTID:10000000107326732674&size=3’
//从第3个开始只显示3个,即3/4/5
curl ‘localhost:9200/power_json/_search?pretty&q=TESTID:10000000107326732674&from=2&size=3’
//按时间排序,desc降序,默认为升序
curl ‘localhost:9200/power_json/_search?pretty&q=TESTID:10000000107326732674&sort=TIME:desc’
//模糊查询
curl ‘localhost:9200/power_json/_search?pretty&analyze_wildcard&q=TESTID:10000000107326732674’
curl ‘localhost:9200/power_json/_search?pretty&q=VAL:<200’ //比较大小
curl ‘localhost:9200/power_json/_search?pretty&_source=false’ //是否显示
curl ‘localhost:9200/power_json/_search?pretty&_source_includes=TIME,VAL’ //设置包含的字段
-g 做转义用
curl -g ‘localhost:9200/power_json/_search?pretty&q=(SOLAR:1%20AND%20CENTRAL:1)’ //组合查询
curl -g ‘localhost:9200/power_json/_search?pretty&q=TIME:[2019-05%20TO%2020-06]’ //范围查询
高级查询
查询某一个索引下面的source的内容
curl -XGET master:9200/bigdata/product/1/_source?pretty
{
“name” : “hadoop”,
“author” : “Doug Couting”,
“lastest_version” : “3.0.0”
}
查询name是hadoop,hbase条件查询
curl -XGET ‘master:9200/bigdata/product/_search?q=name:hadoop,hbase&pretty’
{
“took” : 20,
“timed_out” : false,
“_shards” : {
“total” : 5,
“successful” : 5,
“failed” : 0
},
“hits” : {
“total” : 2,
“max_score” : 0.04500804,
“hits” : [ {
“_index” : “bigdata”,
“_type” : “product”,
“_id” : “1”,
“_score” : 0.04500804,
“_source” : {
“name” : “hadoop”,
“author” : “Doug Couting”,
“lastest_version” : “3.0.0”
}
}, {
“_index” : “bigdata”,
“_type” : “product”,
“_id” : “3”,
“_score” : 0.04500804,
“_source” : {
“name” : “hbase”,
“author” : “apache”,
“lastest_version” : “1.1.5”
}
} ]
}
}
部分字段查询
curl -XGET ‘master:9200/bigdata/product/3?_source=name,author&pretty’
{
“_index” : “bigdata”,
“_type” : “product”,
“_id” : “3”,
“_version” : 1,
“found” : true,
“_source” : {
“author” : “apache”,
“name” : “hbase”
}
}
