elastic-常用语句记录

查询

基本搜索

GET /my_index/my_type/_search
{
  "query": {
    "bool": {
      "must":     { "match": { "title": "quick" }},
      "must_not": { "match": { "title": "lazy"  }},
      "should": [
                  { "match": { "title": "brown" }},
                  { "match": { "title": "dog"   }}
      ]
    }
  }
}

嵌套多层组合查询

{
    "bool": {
        "must":     { "match": { "title": "how to make millions" }},
        "must_not": { "match": { "tag":   "spam" }},
        "should": [
            { "match": { "tag": "starred" }}
        ],
        "filter": {
          "bool": { 
              "must": [
                  { "range": { "date": { "gte": "2014-01-01" }}},
                  { "range": { "price": { "lte": 29.99 }}}
              ],
              "must_not": [
                  { "term": { "category": "ebooks" }}
              ]
          }
        }
    }
}

查询所有字段(_all field)

{
  "query": {
    "query_string": {
      "query": "id:647"
    }
  }
}

根据查询结果删除

POST comment_real_case/comment_real_case/_delete_by_query
{
  "query": { 
    "match_all": {
    }
  }
}
支付宝打赏 微信打赏

来杯咖啡~

文章导航