创建索引
PUT /heima
 {
      “settings”: {
          “number_of_shards”: 3,
          “number_of_replicas”: 2
        }
  }
  查看索引
  get heima
  删除索引
  delete heima
6.创建数据库表
PUT /索引库名/_doc/类型名称
{
  “properties”: {
    “字段名”: {
      “type”: “类型”,
      “index”: true,
      “store”: true,
      “analyzer”: “分词器”
    }
  }
}

PUT heima/_doc/goods1
{
  “properties”: {
    “title”: {
      “type”: “text”,
      “analyzer”: “ik_max_word”
    },
    “images”: {
      “type”: “keyword”,
      “index”: “false”
    },
    “price”: {
      “type”: “float”
    }
  }
}

查看数据库
get heima/_doc/goods
新增字段
POST /索引库名/类型名
{
    “key”:”value”
}
post heima/_doc/goods
{
    “key”:”value”
}
新增数据
POST /heima/goods/                    
{
    “title”:”小米手机”,
    “images”:”http://image.leyou.com/12479122.jpg”,
    “price”:2699.00
   
}

查询数据
GET /heima/_search
{
  “query”: {
    “match_all”: {}
  }
}

多字段查询
GET /heima/_search
{
  “query”: {
    “multi_match”:{
      “query”: “小米手机”,
      “fields”: [“title”,”images”]
    }
  }
}
多词条查询
GET /heima/_search
{
  “_source”: {
    “includes”:[“title”,”price”] 
  },
  “query”: {
    “term”: {
      “price”: 2699
    }
  }
}
范围查找
GET /heima/_search
{
    “query”:{
        “range”: {
            “price”: {
                “gte”:  1000.0,
                “lt”:   2800.00
            }
        }
    }
}
模糊查找
GET /heima/_search
{
  “query”: {
    “fuzzy”: {
        “title”: {
            “value”:”appla”,
            “fuzziness”:1  
        }
    }
  }
}
过滤和拍寻
GET /heima/_search
{
    “query”:{
        “bool”:{
            “must”:{ “match”: { “title”: “小米手机” }},
            “filter”:{
                “range”:{“price”:{“gt”:2000.00,”lt”:3800.00}}
            }
        }
    }
      “sort”: [  //排序
      { “price”: { “order”: “desc” }},//如果价格相同 根据_id排序
      { “_id”: { “order”: “desc” }}
    ]
}
 


版权声明:本文为m0_37825155原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/m0_37825155/article/details/124756637