elasticsearch的部分命令,没有注解

PUT /my_index
GET /_cat/indices?v
GET /my_index

DELETE /my_index


PUT /my_index/_doc/1
{
  "title":"小米手机",
  "category":"小米",
  "price":9999
}

PUT /my_index/_doc/2
{
  "title":"红米手机",
  "category":"小米",
  "price":6666
}

PUT /my_index/_doc/1
{
  "title":"小米手机",
  "category":"小米",
  "price":8888
}

GET /my_index/_doc/1

POST /my_index/_update/1
{
  "doc": {
    "price":1111
  }
}

DELETE /my_index/_doc/2

POST _bulk
{"create":{"_index":"my_index","_id":1}}
{"id":1,"title":"华为手机","category":"华为","price":5500}
{"create":{"_index":"my_index","_id":2}}
{"id":2,"title":"荣耀手机","category":"华为","price":5500}
{"create":{"_index":"my_index","_id":3}}
{"id":1,"title":"小米手机","category":"小米","price":5500}
  
POST _bulk
{"delete":{"_index":"my_index","_id":2}}
{"delete":{"_index":"my_index","_id":3}}
  
GET /my_index
{
  "query":{
    "match":{}
  }
}

GET /_cat/indices?v
  
GET /my_index/_mapping

GET /my_index/_doc/1

#静态映射
PUT /my_index1
{
  "mappings": {
    "properties": {
      "title":{
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_max_word", 
        "type":"text"
      }
    }
  }
}

GET /my_index/_doc/1

POST _bulk
{"create":{"_index":"my_index","_id":4}}
{"id":4,"title":"华为笔记本电脑","category":"华为","price":5388}
{"create":{"_index":"my_index","_id":2}}
{"id":2,"title":"华为手机","category":"华为","price":5500}
{"create":{"_index":"my_index","_id":3}}
{"id":3,"title":"VIVO手机","category":"vivo","price":3600}


POST /my_index/_search
{
  "query": {
    "match_all": {}
  }
}
  
#匹配查询
POST /my_index/_search
{
  "query": {
    "match": {
      "title": "华为"
    }
  }
}

#根据条件删除
POST /my_index/_delete_by_query
{
  "query":{
    "match":{
      "title":"vivo"
    }
  }
}
  
#多字段查找
POST /my_index/_search
{
  "query": {
    "multi_match": {
      "query": "华为智能手机",
      "fields": ["title","category"]
    }
  }
}

POST /my_index/_search
{
  "query": {
    "prefix": {
      "title": {
        "value": "华为手机"
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "term": {
      "title": {
        "value": "华为手机"
      }
    }
  }
}

#多关键字查询
POST /my_index/_search
{
  "query": {
    "terms": {
      "title": [
        "华为",
        "手机"
      ]
    }
  }
}
  
#范围查询
POST /my_index/_search
{
  "query": {
    "range": {
      "price": {
        "gte": 3000,
        "lte": 6000
      }
    }
  }
}

#指定返回字段
POST /my_index/_search
{
  "query": {
    "terms": {
      "title": [
        "华为手机",
        "华为"
      ]
    }
  },
  "_source" : ["title","category"]
}

#组合查询
POST /my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "华为"
          }
        },
        {
          "range": {
            "price": {
              "gte": 3000,
              "lte": 6000
            }
          }
        }
      ]
    }
  }
}

#聚合查询
POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "max_price": {
      "max": {
        "field": "price"
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "min_price": {
      "min": {
        "field": "price"
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "avg_price": {
      "avg": {
        "field": "price"
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "sum_price": {
      "sum": {
        "field": "price"
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0, 
  "aggs": {
    "stats_price": {
      "stats": {
        "field": "price"
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0, 
  "aggs": {
    "groupby_category": {
      "terms": {
        "field": "category",
        "size": 2
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0, 
  "aggs": {
    "groupby_category": {
      "terms": {
        "field": "category",
        "size": 10
      },
      "aggs": {
        "avg_price": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
  }
}

POST /my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "华为"
          }
        }
      ]
    }
  },
  "sort": [
    {
      "price": {
        "order": "asc"
      }
    }
  ]
}

POST /my_index/_search
{
  "query": {
    "match_all": {}
  },
  "from": 0,
  "size": 2
}

POST /my_index/_search
{
  "query": {
    "match": {
      "title": "华为"
    }
  },
  "highlight": {
    "fields": {
      "title": {}
    }
  }
}

PUT /test

PUT /test/_doc/1
{
  "title":"hello"
}

GET /test/_search
{
  "query": {
    "fuzzy": {
      "title": {
        "value": "he"
      }
    }
  }
}

POST /my_index/_mapping
{
  
}

GET /user2
POST /user2/_search
{
  "query": {
    "match_all": {}
  }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值