ElasticSearch学习

ElasticSearch学习

分组:

按series_name字段分组取前几条数据:

{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "request_time": {
              "gt": "2019-07-03",
              "lt": "2019-07-05"
            }
          }
        },
        {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "province_code": {
                    "query": "00644"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "aggs": {
    "group_by_series_name": {
      "terms": {
        "field": "series_name.keyword",
        "size": 5,
        "order": {
          "_count": "desc"
        }
      }
    }
  },
  "size": 0
}
View Code

match_all: 全部查询

GET dw_app_car_offering_price_ds/_search
{
  "query": {
    "match_all": {}
  }
}
View Code

单个查询

GET dw_app_car_offering_price_ds/_search
{
  "query": {
      "term": {
      "model_code": {
        "value": "12550-n"
      }
    }
  }
}
View Code

size:默认10条

GET dw_app_car_offering_price_ds/_search
{
  "query": {
      "term": {
      "model_code": {
        "value": "12550-n"
      }
    }
  },
  "size": 20
}
View Code

from  size :从某个from索引的size条数据

GET dw_app_car_offering_price_ds/_search
{
  "query": {
      "term": {
      "source": {
        "value": "che168"
      }
    }
  },
  "from": 10, 
  "size": 10
}
View Code

sort  :排序

GET dw_app_car_offering_price_ds/_search
{
  "query": {
    "bool": {
      "must": [
        
        {
          "term": {
          "model_code": {
            "value": "201795"
          }
          }
          
        },
        {
          "term": {
            "source": {
              "value": "che168"
            }
          }
        },
        {
          "term": {
            "city_code": {
              "value": "00002"
            }
          }
        }
        
      ]
    }
  },
  "size": 100,
  "sort": [
    {
      "ds": {
        "order": "desc"
      }
    }
  ]
}
View Code

_source:条件查询

GET dw_app_car_offering_price_ds/_search
{
  "query": {
      "term": {
      "model_code": {
        "value": "12550-n"
      }
    }
  },
  "_source": ["offering_price_50","city_code"]
}
View Code

 参考:https://www.cnblogs.com/pilihaotian/p/5830754.html

2.0的语法:

http://www.ischoolbar.com/EsParser/

原文地址:https://www.cnblogs.com/wanghongye/p/10993627.html