Basic syntax of Elasticsearch

Note: The software based on the windows platform is as follows:

image.png

image.png

1. Basic grammar (based on kibana visualization platform plug-in)

1. Get health value

GET /_cat/health?v

GET /_cat/health?help

GET /_cat/indices?v

GET /_cat/indices?v&h=health,status,index

2. Create index and delete index

PUT /zfg

DELETE /zfg

PUT /zfg

{

  "mappings": {

    "_doc": {

      "properties": {

        "age": {

                    "type": "integer"

       },

       "sex": {

                    "type": "keyword"

       },

                     "area": {

                    "type": "keyword"

       },

      "label": {

                    "type": "text"

       },

      "address": {

                    "type": "text"

       },

       "name": {

                    "type": "text"

       },

        "created":  {

          "type":   "date",

          "format": "strict_date_optional_time||epoch_millis"

        }

      }

    }

  }

}

GET /zfg/_mapping/_doc

3. Insert and query a single document

PUT /zfg/_doc/1

{

"name":"徐凤年",

"age":18,

"sex":"男",

"area":"北凉",

"label":" Beiliang Wang Shizi",

"address":" Qingliang Mountain Beiliang King's Mansion",

"dynamic_wg":[{"wgname":"Two Sleeves Green Snake","wgzl":"Swordsmanship","wgsc":"Li Chungang"},{"wgname":"Twelve Flying Swords","wgzl": "Royal Swordsmanship","wgsc":"Deng Tai Ah"}]

}

GET /zfg/_doc/1

POST /zfg/_doc

{

"name":"徐骁",

"age":50,

"sex":"男",

"area":"北凉",

"label":" Old Liang Wang, Dazhu Kingdom",

"address":" Qingliang Mountain Beiliang King's Mansion",

"dynamic_wg":[{"wgname":"无","wgzl":"无","wgsc":"无"}]

}

POST /zfg/_doc/_search

{

  "size":10,

  "query":{

    "match_all": {}

  }

}

POST /zfg/_doc/_search

{

  "query":{

    "match": {"name":"姜泥"}

  }

}

4. Insertion and query of multiple documents (note that to insert multiple documents, the index must be enabled and only one line is effective, so the document information must be written on one line to be effective)

POST /zfg/_doc/_bulk

{"index":{}}

{"name":" Wen Hua","age":18,"sex":"Male","area":"Jiangnan","label":"Youxia","address":"No fixed home" ,"dynamic_wg":[{"wgname":"Mysterious Two Swords","wgzl":"Swordsmanship","wgsc":"Suixie Valley"}]}

{"index":{}}

{"name":" Xuanyuan Qingfeng","age":18,"sex":"女","area":"Huishan","label":"Master of Huishan Daxueping","address" :"Huishan Daxueping Xuanyuan Family","dynamic_wg":[{"wgname":"Miscellaneous Studies","wgzl":"无","wgsc":"Xuanyuan Family Studies"}]}

{"index":{}}

{"name":"姜泥","age":18,"sex":"女","area":"Da Chu","label":"Da Chu Subjugated Princess","address":"Qingliang Shanbei Liangwangfu","dynamic_wg":[{"wgname":"Royal Swordsmanship","wgzl":"Royal Swordsmanship","wgsc":"Li Chungang"}]}

{"index":{}}

{"name":" Huang Fangfo","age":40,"sex":"Male","area":"Huishan","label":"Xuanyuan Family Guest Qing","address":"Qingliang Shanbei Liangwangfu","dynamic_wg":[{"wgname":"Royal Swordsmanship","wgzl":"Royal Swordsmanship","wgsc":"Li Chungang"}]}

{"index":{}}

{"name":"贺铸","age":35,"sex":"男","area":"EE","label":"游侠","address":"EE","dynamic_wg":[{"wgname":"肝胆剑","wgzl":"剑术","wgsc":"李淳罡"}]}

5. Query different information

POST /zfg/_doc/_search

{

  "query":{

    "multi_match": {

      "query":"山",

      "fields": ["area","address"]

    }

  }

}

POST /zfg/_doc/_search

{

  "query":{

    "match": {

      "sex": "女"

    }

  }

}

6. Sort and display paging data

POST /zfg/_doc/_search

{

  "from":"0",

  "size":"100"

}

POST /zfg/_doc/_search

{

  "from":"0",

  "size":"100",

  "sort":[

  {

    "_score":{

      "order":"desc"

    }

  }

  ]}


Guess you like

Origin blog.51cto.com/14049943/2679117