本文介绍使用阿里云Elasticsearch(简称ES)服务搜索数据的方法,包括全文搜索和按查询条件搜索。

按查询条件搜索

执行如下命令搜索年化率在3.0000%到3.1300%之间的产品。

GET /product_info/products/_search
{
  "query": {
    "range": {
      "annual_rate": {
        "gte": "3.0000%",
        "lte": "3.1300%"
      }
    }
  }
}

执行成功后,返回结果如下。

{
  "took" : 10,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "product_info",
        "_type" : "products",
        "_id" : "WLvWYXAB8Rql5AUxLqUU",
        "_score" : 1.0,
        "_source" : {
          "productName" : "西部通宝",
          "annual_rate" : "3.1100%",
          "describe" : "90天定投产品,最低10000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "products",
        "_id" : "WrvWYXAB8Rql5AUxLqUU",
        "_score" : 1.0,
        "_source" : {
          "productName" : "5G设备采购月月盈",
          "annual_rate" : "3.1200%",
          "describe" : "90天定投产品,最低12000起投,每天收益到账消息推送"
        }
      }
    ]
  }
}

ES会根据条件搜索到符合预期的产品,同时以降序排列展示。

更多查询方法请参见Query DSL