ES常用指令

#显示各个分片的状态
GET /_cat/shards?v
#显示集群健康值
GET /_cluster/health
#新建索引
PUT /test_index?pretty
#查询所有索引
GET /_cat/indices?v
#删除索引
DELETE /test_index?pretty
#排序
GET /product/_search?sort=price:desc
#关键词查询+排序
GET /product/_search?q=name:phone&sort=price:desc
#查询id是1的数据
GET /product/_doc/1
#分页查询,排序,超时设置,到达时间以后,查询出多少数据,就显示多少数据
GET /product/_search?from=0&size=2&sort=price:desc&timeout=1ms
#查询全部
GET /product/_search
{
  "query": {
    "match_all": {}
  }
}
#排序查询
GET /product/_search
{
  "query": {
    "match": {
      "name": "nfc"
    }
  },
  "sort": [
    {
      "price": {
        "order": "desc"
      }
    }
  ]
}
#在多个字段中查询关键词
GET /product/_search
{
  "query": {
    "multi_match": {
      "query": "nfc",
      "fields": ["name","desc"]
    }
  },
  "sort": [
    {
      "price": {
        "order": "desc"
      }
    }
  ],
  "from": 1,
  "size": 2
}
#查询显示特定字段
GET /product/_search
{
  "query": {
    "match": {
      "name": "nfc phone"
    }
  },
  "sort": [
    {
      "price": "desc"
    }
  ],
  "_source": ["name","price"]
}
#term不支持查询关键词的自动分词,同时也说明,es的查询是根据分词查询的
GET /product/_search
{
  "query": {
    "term": {
      "name": "nfc phone"
    }
  }
}
GET /product/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "name":"nfc"
          }
        },
        {
          "term": {
            "name": {
              "value": "phone"
            }
          }
        }
      ]
    }
  }
}
#terms的多关键词查询,类似于in,相当于人工分词
GET /product/_search
{
  "query": {
    "terms": {
      "name": [
        "nfc",
        "phone"
      ]
    }
  }
}
GET /product/_search
{
  "query": {
    "match": {
      "name": "nfc phone"
    }
  }
}
#match会进行分词查询
GET /product/_search
{
  "query": {
    "match": {
      "name": "xiaomi nfc zhineng phone"
    }
  }
}
#默认分词器
GET /_analyze
{
  "analyzer": "standard",
  "text": ["xiaomi nfc zhineng phone"]
}

PUT /product/_doc/1
{
    "name" : "xiaomi phone",
    "desc" :  "shouji zhong de zhandouji",
    "price" :  3999,
    "tags": [ "xingjiabi", "fashao", "buka" ]
}
POST /product/_doc/1/_update
{
  "doc":{
    "price":2999
  }
}
PUT /product/_doc/2
{
    "name" : "xiaomi nfc phone",
    "desc" :  "zhichi quangongneng nfc,shouji zhong de jianjiji",
    "price" :  4999,
    "tags": [ "xingjiabi", "fashao", "gongjiaoka" ]
}


PUT /product/_doc/3
{
    "name" : "nfc phone",
    "desc" :  "shouji zhong de hongzhaji",
    "price" :  2999,
    "tags": [ "xingjiabi", "fashao", "menjinka" ]
}

PUT /product/_doc/4
{
    "name" : "xiaomi erji",
    "desc" :  "erji zhong de huangmenji",
    "price" :  999,
    "tags": [ "low", "bufangshui", "yinzhicha" ]
}

PUT /product/_doc/5
{
    "name" : "hongmi erji",
    "desc" :  "erji zhong de kendeji nfc",
    "price" :  399,
    "tags": [ "lowbee", "xuhangduan", "zhiliangx" ]
}

猜你喜欢

转载自blog.csdn.net/weixin_44182586/article/details/115364488
今日推荐