This topic describes how to use Alibaba Cloud Elasticsearch (ES) to perform complex searches.

Use the Kibana console to access Alibaba Cloud Elasticsearch, and send the following request to perform a complex search.
  • Search by time range:
    GET /my_index/_search? pretty
    {
        "query" : {
            "range" : {
                "post_date" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
            }
        }
    }
    If the request is successful, the following result is returned:
    {
      "took" : 7,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 2,
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "title" : "Two",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T14:00:00"
            }
          },
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "title" : "One World",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T13:00:00"
            }
          }
        ]
      }
    }
  • Search by keyword:
    GET /my_index/_search? pretty
    {
        "query" : {
        "simple_query_string" : {
            "query": "One +(python | ruby) -Two",
            "fields": ["title^5", "tags"],
            "default_operator": "AND"
        }
      }
    }
    If the request is successful, the following result is returned:
    {
      "took" : 8,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 1,
        "max_score" : 2.7260926,
        "hits" : [
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "1",
            "_score" : 2.7260926,
            "_source" : {
              "title" : "One World",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T13:00:00"
            }
          }
        ]
      }
    }