API operation based on Restful style

API operation based on Restful style

Index operation
Add index:
put _index(index)
{ parameters }

Query index:
get _index

Delete index:
delete _index

Mapping management
put index/_mapping/

Data management
//Create index library
put index library
//Create mapping relationship (table)
put tiao/_mapping/book
{ "properties":{ "title":{ "type":"text", "analyzer":"ik_max_word" }, "images":{ "type":"keyword" }, "price":{ "type":"float" } } }












data query

1. Query by id
Syntax 1: Query all by id (select *)
get index name/type/id

Syntax 2: Query part by id (select field 1, field 2...)
get index number/type/ID?_source=field 1, field 2

2. Query all
Syntax 1: Query all contents of all index libraries
get _search
{ "query" :{ "match_all": { } } }




Syntax 2: Query all the contents of the specified library
get index library/_search
{ "query" :{ "match_all": { } } }




Syntax 3: Query part of the contents of the specified library

get index library/_search
{ "query" :{ "match_all": { } }, "_source": ["title","price"] }





3. Keyword query match
Query through the conditions specified by match, es scores the weight of each result, the higher the score, the higher the ranking

Syntax 1
get index library/_search
{ "query" :{ "field": "value" } }



Syntax 2 Query
get index library according to id /_search
{ "query" :{ "match":{ "_id": "id number" } } }





4. Multi-condition query must, must_not (intersection)

You need to use bool to piece together multiple conditions.
If the condition is necessary, you need to use must.
If the condition is not needed, use must_not (the query result cannot have)

Syntax:
get index/_search
{ "query" :{ "bool" :{ condition 1, condition 2 } } }






get index/_search
{ "query" :{ "bool" :{ "must" :[ {condition1},{condition2}], //Required "must_not":[{condition1},{condition2}] //Not required } } }






5. Multi-condition query: should (union)

Syntax:
get index/_search
{ "query": { "bool": { "should" :[ { "must" :{ "title": "value" } }, { "must":{ "price": "123 ”} } ] } } }















6 Precise query (term)
Precise query: exact match query, use term to complete
term: precise query Data type requirements: number, date, boolean, string (no word segmentation)
Syntax:
get index/_search
{ "query":{ "term ":{ Condition } } }





term and match comparison
match keyword query (matching query) results without word segmentation query
term exact query, word segmentation is not supported

7 Range query (range)
Range query: equivalent to sql between
range keywords: gt greater than / lt less than /get greater than or equal to /let less than or equal to
get index /_search
{ "query":{ "range":{ "field":{ Keyword: value } } } }







8Sort Query (sort)
Sort: perform secondary processing on query results
Syntax:
get index/_search
{ "query":{ "match_all":{ } }, "sort":[ { "field":{"order": "Asc/dsc"} } ] }









9 Paging query (from+size)
Paging: Query all, data
syntax: get index/_search
{ "query" :{ "match_all":{ }, "from":0, //start index from 0 "size ”:2 //How many items are displayed on each page } }






Delete data: delete

Syntax:
delete index library/type/ID

Update or add data: ID (put request)

Syntax:
If the id already exists, update the data
If the id does not exist, add the data

First add setting id
put index library/type/ID
{ "field": "value" }

The second addition is to change the
put index library/type/ID
{ "field":"value" }

Guess you like

Origin blog.csdn.net/weixin_43464372/article/details/105436141