查看索引列表: http://127.0.0.1:9200/_cat/indices?v
------------恢复内容开始------------
查看索引列表: http://127.0.0.1:9200/_cat/indices?v
新建索引:put http://127.0.0.1:9200/shopping
新建内容 :post http://127.0.0.1:9200/shopping/_doc
新建定义ID数据: post http://127.0.0.1:9200/shopping/_doc/id
查询所有:get http://127.0.0.1:9200/shopping/_search
覆盖内容: put http://127.0.0.1:9200/shopping/_doc/id
局部更新:post http://127.0.0.1:9200/shopping/_update/1001
{
"doc":{
"title":"华为手机"
}
}
条件查询
查询索引总条数
GET /vehicle/_count
{
}
get http://127.0.0.1:9200/shopping/_search?q=category:小米
get http://127.0.0.1:9200/shopping/_search
局部查询 {
"query":{
"match":{
"category":"小米"
}
}
}
模糊查询
GET vehicle/_search
{
"query":{
"wildcard":{
"vlpncolor.keyword":{
"value":"*01*"
}
}
}
}
精准查询
GET vehicle/_search
{
"track_total_hits":true,
"query": {
"bool": {
"must": [
{ "term": { "vlpn.keyword": "测YG3146" }},
{ "term": { "vlpncolor.keyword": "01" } }
]
}
}
}
全量查询
{
"query":{
"match_all ":{
}
},
"from":0,
"size":2,
"_source":["title"], //返回列
"sort":{
"price":{
"order":"desc"
}
}
}
多条件查询,范围查询
{
"query":{
"bool":{
"must":[ //多条件满足 should //单条件满足
{
"match":{
"category":"小米"
}
}
],
"filter":{
"range":{
"price":{
"gt":5000
}
}
}
}
}
}
全文匹配,完全匹配,高亮匹配
{
"query":{
"match_phrase":{
" category":"xx"
}
},
"highlight":{
"fields":{
"category":{}
}
}
}
聚合查询
{
"aggs":{
"price_group":{ // price_avg
"terms":{ //avg
"field":"price"
}
}
},
"size":0
}
GET /vehicle/_search
{
"size" : 0,
"aggs" : {
"popular_colors" : {
"terms" : {
"field" : "attention"
}
}
}
}
映射关系
get http://127.0.0.1:9200/user/_mapping
{
"properties":{
"name":{
"type":"text",
"index":true //可被索引查询
},
"sex":{
"type":"keyword", //非模糊查询
"index":false //不可被索引查询
}
}
}
//索引增加字段
PUT vehicle/_mapping/_doc?include_type_name=true
{
"properties": {
"VehicleID": {
"type": "long"
}
}
}
------------恢复内容结束------------