Search API

Specifies the index of the query

1.We need to put that in the URL_search indicates that this operation is a query operationCopy the code
grammar The scope of
/_search All indexes on the cluster
/index1/_search index1
/index1,index2/_search Index1 and index2
/index*/_search An index that starts with index

URI Search

Query string syntax is kv key/value pair. # df can be used to specify the query field. # sort can be used to specify the field sort. For example, year:desc, in descending order of year # form and size are used for paging # profile to see examples of how queries are executed: GET /movies/_search (' search ', 'search'); q=year:1995GET /movies/_search; q=1995Term is included in query year1995or2021GET /movies/_search? q=year:(1995 2021Select * from Term1995, or all field values contain2021(2021GET /movies/_search? q=year:1995 2021# Phrase query year1995And contain2021GET /movice/_search? q=year:"1995, 2021"GET /movice/_search? {} GET /movice/_search? q=year:[1995 TO 2021] GET /movice/_search? Q =year:{1995 TO 2021} # GET /movice/_search? q=year:>1995GET /movice/_search? q=year:(>1995&& < =2021GET /movice/_search? q=year:19?5#? One character GET /movice/_search? q=year:19*5#? said0Or multiple characters # fuzzy matching GET /movice/_search? q=title:hvae~1GET /movice/_search? q=title:Lord Rings~2# Retrieve documents with two words between Lord and RingsCopy the code

Request Body Search

# 1.Use Elasticsearch provided based onJSONA more complete Query Domain Specific Language(DSL) format #2.Some advanced queries can only be done through the Request Body, so use this example: # paginationfromfrom0Start, return by default10POST /movies/_search {POST /movies/_search {"from":10."size":20."query": {"match_all"POST /movies/_search {POST /movies/_search {"sort": [{"order_date":"desc"}]."from":10."size":20."query": {"match_all"POST /movies/_search :{}} /movies/_search;"_source": ["order_date"."date"]."from":10."size":20."query": {"match_all"Scoure supports wildcard _source["name*"."desc*"]

Copy the code

Batch query msearch

POST test/_msearch
{}
{"query": {"match_all": {}},"size":2}
{"index":"test2"} # specify another index query {"query": {"match_all": {}},"size":1} The response results are as follows: {"took" : 61."responses": [{"took" : 44."timed_out" : false."_shards" : {
        "total" : 1."successful" : 1."skipped" : 0."failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1."relation" : "eq"
        },
        "max_score" : 1.0."hits": [{"_index" : "test"."_type" : "_doc"."_id" : "1"."_score" : 1.0."_source" : {
              "field1" : "value2"}}},"status" : 200
    },
    {
      "took" : 45."timed_out" : false."_shards" : {
        "total" : 1."successful" : 1."skipped" : 0."failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1."relation" : "eq"
        },
        "max_score" : 1.0."hits": [{"_index" : "test2"."_type" : "_doc"."_id" : "3"."_score" : 1.0."_source" : {
              "field1" : "value3"}}},"status" : 200}}]Copy the code

More content welcome to pay attention to my personal public number “Han Elder brother has words”, 100G artificial intelligence learning materials, a large number of back-end learning materials waiting for you to take.