Tips: Computer can not see the end to the right directory, then reduce the zoom ratio.
API operations - new or delete query index database
New index Library
New index, would like to send a PUT request the server, using the following command creates a curl index named test examples
curl -XPUT 'localhost:9200/test'
Response:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "test"
}
Delete index Library
Delete the index, the server would like to send a delete request, delete the following index is an example of the above test
curl -XDELETE 'http://localhost:9200/customer'
Response:
{
"acknowledged": true
}
Query index Library
Query index, to send a HEAD request, the following examples
curl -IHEAD 'localhost:9200/test'
Answer:
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 359
API operations - the mapping between
Next Steps with curl more inconvenient, complex content using PostMan operation, to be used to create a mapping between PUT request, the following code representing json I define three fields, namely, title, url and doc, their type attribute that is data types, data types on elasticsearch here, but many go, analyzer uses the word ik's most coarse-grained segmentation is representative of ik_max_word
PUT test/_mapping
{
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"url": {
"type": "text"
},
"doc": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
Answer:
{
"acknowledged": true
}
API operations - the query mapping relationship
Mapping relational query index database to use GET request, as I query the mapping relationship created above
curl -XGET 'localhost:9200/test/_mapping'
Response:
{
"test" : {
"mappings" : {
"properties" : {
"doc" : {
"type" : "text",
"analyzer" : "ik_max_word"
},
"title" : {
"type" : "text",
"analyzer" : "ik_max_word"
},
"url" : {
"type" : "text"
}
}
}
}
}
API - to add update data
adding data
Adding data using a GET request json data to the index above the library, for example, I added the following data
GET test/_doc
{
"title": "PlumK's blog",
"url": "plumk.site",
"doc": "this is the content,这里是正文"
}
update data
Update the data need to know id data can be obtained by finding other add data with similar, GET request http://localhost:9200/test/_doc/bm87BW8BcAj1cF19_7Sf
json as follows :( bm87BW8BcAj1cF19_7Sf here is what I have to insert the data id)
GET test/_doc/bm87BW8BcAj1cF19_7Sf
{
"title": "PlumK's blog",
"url": "plumk.site",
"doc": "this is the content,这里是修改后的正文"
}
Response:
{
"_index": "test",
"_type": "_doc",
"_id": "bm87BW8BcAj1cF19_7Sf",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
API operations - delete data
Delete data also need to know the id, to remove the above data, for example, send a DELETE request to the following url:
localhost:9200/test/_doc/bm87BW8BcAj1cF19_7Sf
API operations - the query data
match all queries
The most basic query, he would return all results, scores of each object 1
POST /test/_search
{
"query":{
"match_all":{}
}
}
Response:
{
"took": 9,
"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": "bm87BW8BcAj1cF19_7Sf",
"_score": 1.0,
"_source": {
"title": "PlumK's blog",
"url": "plumk.site",
"doc": "this is the content,这里是正文"
}
}
]
}
}
match query
match queries return match in the same property entry, the following url if it is plumk can not find, and that is exactly the same property must
POST test/_search
{
"query": {
"match": {
"url": "plumk.site"
}
}
}
Answer:
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "bm87BW8BcAj1cF19_7Sf",
"_score": 0.2876821,
"_source": {
"title": "PlumK's blog",
"url": "plumk.site",
"doc": "this is the content,这里是修改后的正文"
}
}
]
}
}
Query String query
The query uses the query parser and query_string keywords. For example:
POST test/_search
{
"query": {
"query_string": {
"query": "plumk"
}
}
}
Response:
{
"took": 25,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "bm87BW8BcAj1cF19_7Sf",
"_score": 0.2876821,
"_source": {
"title": "PlumK's blog",
"url": "plumk.site",
"doc": "this is the content,这里是修改后的正文"
}
}
]
}
}
Set the minimum matching query
Set minimum_should_match field, if this match will be the degree to satisfy the query out, not much nonsense, look at an example
GET test/_search
{
"query": {
"match": {
"title":{"query": "plumk的博客","minimum_should_match": "50%"}
}
}
}
Multi-field queries
Try searching here in the url and title inplumk
GET test/_search
{
"query": {
"multi_match": {
"query": "plumk",
"fields": ["url", "title"]
}
}
}
I am going to the next query may not use, but considering there just to get into the same white see this blog, so here I was the following excerpt from the Internet
Term inquiry
Structured data queries mainly deal with numbers, dates, and so on. as follows:
POST /schools/_search
{
"query":{
"term":{"zip":"176115"}
}
}
Answer:
{
"took":1, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
"hits":{
"total":1, "max_score":0.30685282, "hits":[{
"_index":"schools", "_type":"school", "_id":"1", "_score":0.30685282,
"_source":{
"name":"Central School", "description":"CBSE Affiliation",
"street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
"location":[31.8955385, 76.8380405], "fees":2200,
"tags":["Senior Secondary", "beautiful campus"], "rating":"3.3"
}
}]
}
}
Range Queries
This query is used to find the value of an object between the range of values. To this end, we need to use the following operators
- gte: greater than or equal
- gt: greater than
- lte: less than or equal
- lt: less than
POST /schools*/_search
{
"query":{
"range":{
"rating":{
"gte":3.5
}
}
}
}
Response:
{
"took":31, "timed_out":false, "_shards":{"total":10, "successful":10, "failed":0},
"hits":{
"total":3, "max_score":1.0, "hits":[
{
"_index":"schools", "_type":"school", "_id":"2", "_score":1.0,
"_source":{
"name":"Saint Paul School", "description":"ICSE Affiliation",
"street":"Dawarka", "city":"Delhi", "state":"Delhi",
"zip":"110075", "location":[28.5733056, 77.0122136], "fees":5000,
"tags":["Good Faculty", "Great Sports"], "rating":"4.5"
}
},
{
"_index":"schools_gov", "_type":"school", "_id":"2", "_score":1.0,
"_source":{
"name":"Government School", "description":"State Board Affiliation",
"street":"Hinjewadi", "city":"Pune", "state":"MH", "zip":"411057",
"location":[18.599752, 73.6821995] "fees":500,
"tags":["Great Sports"], "rating":"4"
}
},
{
"_index":"schools", "_type":"school", "_id":"3", "_score":1.0,
"_source":{
"name":"Crescent School", "description":"State Board Affiliation",
"street":"Tonk Road", "city":"Jaipur", "state":"RJ", "zip":"176114",
"location":[26.8535922, 75.7923988], "fees":2500,
"tags":["Well equipped labs"], "rating":"4.5"
}
}
]
}
}
Composite Query
This is more complex, there is not too much to say, you can look at this blog
There are also Joining query, this involves nested maps, do not start speaking up, as well as geographical inquiry, being less than, you can go to the official documentation
To be continued. . .