1. Description
Query the API message body elasticsearch search for content, the user can search by sending a query string parameter in the get request, the request may be in the post.
2. Multi-Index
Allow search index or all of certain documents in the index.
For example: Search name contains tom1 documents in a multi-index.
① in a multi-index search
1 GET /index1,index2,index3/_search?q=name:tom1
effect:
1 { 2 "took" : 1, 3 "timed_out" : false, 4 "_shards" : { 5 "total" : 3, 6 "successful" : 3, 7 "skipped" : 0, 8 "failed" : 0 9 }, 10 "hits" : { 11 "total" : { 12 "value" : 2, 13 "relation" : "eq" 14 }, 15 "max_score" : 0.2876821, 16 "hits" : [ 17 { 18 "_index" : "index1", 19 "_type" : "_doc", 20 "_id" : "1", 21 "_score" : 0.2876821, 22 "_source" : { 23 "name" : "tom1", 24 "sex" : "M", 25 "address" : "SH" 26 } 27 }, 28 { 29 "_index" : "index2", 30 "_type" : "_doc", 31 "_id" : "1", 32 "_score" : 0.2876821, 33 "_source" : { 34 "name" : "tom1", 35 "age" : 20 36 } 37 } 38 ] 39 } 40 }
② full index searches
You can not add _all
1 GET /_search?q=name:tom1
effect:
1 { 2 "took" : 4, 3 "timed_out" : false, 4 "_shards" : { 5 "total" : 9, 6 "successful" : 9, 7 "skipped" : 0, 8 "failed" : 0 9 }, 10 "hits" : { 11 "total" : { 12 "value" : 3, 13 "relation" : "eq" 14 }, 15 "max_score" : 0.2876821, 16 "hits" : [ 17 { 18 "_index" : "index1", 19 "_type" : "_doc", 20 "_id" : "1", 21 "_score" : 0.2876821, 22 "_source" : { 23 "name" : "tom1", 24 "sex" : "M", 25 "address" : "SH" 26 } 27 }, 28 { 29 "_index" : "index2", 30 "_type" : "_doc", 31 "_id" : "1", 32 "_score" : 0.2876821, 33 "_source" : { 34 "name" : "tom1", 35 "age" : 20 36 } 37 }, 38 { 39 "_index" : "school", 40 "_type" : "_doc", 41 "_id" : "1", 42 "_score" : 0.18232156, 43 "_source" : { 44 "name" : "tom1", 45 "sex" : "M", 46 "age" : "20" 47 } 48 } 49 ] 50 } 51 }
3.URL search
2 multi index examples, in fact, simply use the URI is used to perform a search request.
Parameters used in the above is q, the following are some of the request parameters may be used, as follows:
-
Q: the search for a string to specify
-
lenient: If this parameter is set to true, you can ignore the error based format. By default, it is false.
-
fields: This parameter help us get a response from the selective field.
-
sort: We can change the sort the results by using this parameter, the value of this parameter allows field names: ASC / field names: desc
-
timeout: We can limit the search time by using this parameter, and the response contains only hit within a specified time. By default, do not specify a timeout.
-
terminate_after: For each slice, we can respond is limited to a specified number of documents, once they reach this number, the query will terminate early. By default, it does not specify terminate_after.
-
from: the beginning of the return from the specified index defaults to 0.
-
size: indicates the number of records to return the default is 10.
4. Query request body