Elasticsearch Fourth article (API Convention) _elasticsearch

Source: Internet
Author: User
Tags uuid
To operate on multiple indices

Most Resetapi in ES support request multiple index, such as "Test1,test2,test3", index can also use wildcard characters, such as "test*", can also use +,-to include or remove a certain type of index, such as "test*,- Test1 "
The request string that supports setting up multiple APIs can set the following parameters: Ignore_unavailable: Ignore whether a single index is available (not present or closed), true to ignore, false to not ignore, default to False, for example, the query has closed index :

Input: Get/test1/user,account/_search?ignore_unavailable=false
Output:

1
2
3
4
{
   "error": "Indexclosedexception[[test1] closed]",
   "status": 403
}

Input: Get/test1/user,account/_search?ignore_unavailable=false
Output:

1
2
3
4
5
6 7 8 9 (14)
{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 0,
      "successful": 0,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "Max_score": 0,
      "hits": []
   }
}

Allow_no_indices: Whether the wildcard match is not matched to index (not present or closed), true is allowed, false indicates not allowed, default is true, for example, the query has closed index:

Input: Get/test*/_search?allow_no_indices=false
Output:

1
2
3
4
{
   "error": "indexmissingexception[[test*] missing]",
   "status": 404
}

Input: Get/test*/_search?allow_no_indices=true

1
2
3
4
5
6 7 8 9 (14)
{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 0,
      "successful": 0,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "Max_score": 0,
      "hits": []
   }
}
Expand_wildcards: Set whether to extend wildcard characters to Closed's index, open means to query only in matches and open index, closed for all matching index, default is closed, For example, the query has been closed by index
Input: get/test*/_search?expand_wildcards=closed
Output:
1
2
3
4
{
   "error": "Indexclosedexception[[test1] closed]",
   "status": 403
}
Public parameters

Format: Represents the formatting of the returned data, with an optional value of YAML and JSON two, for example:
Input: Get/test1/user/_search?format=yaml
Output:

1
2
3
4
5
6 7 8 9 (16)
17
---
took:23
timed_out:false
_shards:
  total:5
  successful:5
failed:0 Hits:
  total:1
  max_score:1.0
  Hits:
  -_index: "Test1"
    _type: "User"
    _id: "1"
    _score: 1.0
    _source:
      name: "Silence"

Pretty: Indicates whether to return the data in a JSON format in a visual format, false or not in the format of the formatting, otherwise format

Human: Indicates whether the return result is formatted, such as 3600 (s) display 1h

Query result filtering
Use the Filter_path parameter mainly to set up

1. In the return results we only focus on took, Hits.total, hits.hits._id, Hits._source, we can initiate such a request:
Input: Get/test1/user/_search?filter_path=took,hits.total,hits.hits._id,hits.hits._source
Output:

1
2
3
4
5
6 7 8 9 (14)
{
   "took": 1,
   "hits": {
      "total": 1,
      "hits": [
         {
            "_id": "1",
            "_source": {
               "name": " Silence "}}
      ]
   }
}

2. You can also use the wildcard character to set
Input: Get/_nodes/stats?filter_path=nodes.*.*ost*,nodes.*.os.*u
Output:

1
2
3
4
5
6 7 8 9 (15)
16
{"
   nodes": {"9jfw4vewrta-uq7cq7bk34": {"
         Host": "Silence",
         "OS": {
            "CPU": {
               "sys": 1,
               "User": 1, "
               idle": "
               Usage": 2,
               "stolen": 0
            }
}}

3. Use * * For simplification if there is more hierarchy
Input: Get/_nodes/stats?filter_path=nodes.**.*sys*
Output:

1
2
3
4
5
6 7 8 9 (15)
16
{"Nodes": {"9jfw4vewrta-uq7cq7bk34": {"OS": {"CPU": {"
               sys": 2
            }
         },
         "process": {
            ' CPU ': {
               ' sys_in_millis ': 139106
            }
         }
   }}

4. If only some of the values in the _source are required, the Filter_path and _source parameters can be used together
Input: get/test1/account/_search?filter_path=hits.hits._source&_source=firstname,lastname,gender&size=2
Output:

1
2
3
4
5
6 7 8 9 (15)
20
{"
   hits": {"
      hits": [
         {"
            _source": {"
               FirstName": "Rodriquez",
               "gender": "F",
               " LastName ":" Flores "
            }
         },
         {"
            _source ": {"
               FirstName ":" Opal ",
               " gender ":" M ",
               " LastName ': ' Meadows '}}}}

5.flat_settings is used to set the key format in setting when querying setting, which defaults to false:
Input: Get/test1/_settings?flat_settings=true
Output:

1
2
3 4 5 6 7 8 9
Ten
11
{"
   test1": {"settings": {"
         index.creation_date": "1442230557598",
         "Index.uuid": " 70bg061irdkuddnvgkuboq ",
         " index.version.created ":" 1060099 ",
         " Index.number_of_replicas ":" 1 ",
         " Index.number_of_shards ': ' 5 '}}}

Input: Get/test1/_settings?flat_settings=false
Output:

1
2
3
4
5
6 7 8 9 (15)
{"
   test1": {"settings": {"
         index": {"
            creation_date": "1442230557598",
            "number_of_shards ":" 5 ",
            " uuid ":" 70bg061irdkuddnvgkuboq ",
            " version ": {
               " created ":" 1060099 "
            },
            " number_of _replicas ":" 1 "}}}}

Request parameter Format
1.boolean: In Es, "0", 0, False, "false", "off" is recognized as false, others are treated as ture
2.number
3.time: You can submit an integer with a millisecond time or a string that ends with a date. For example "2d" means 2 days, supported formats are: Y (year), M (month), W (week), D (Day), H (Hour), M (minute), S ( Second
4. Distance: You can submit a certificate in meters or a string that ends at a distance, for example, "2km" means 2-kilometer, and the supported formats are: Mi/miles (mile miles), Yd/yards (yard code), Ft/feet (feet ruler), In/inch ( inch inches), km/kilometers (kilometer km), m/meters (meter m), cm/centimeters (centimeter cm), mm/millimeters (millimeter mm), Nm/nmi/nauticalmiles (nautical mile nanometer)
5. Fuzzy Type:
A. Number, time, IP: similar to Range-fuzzines<=value<=+fuzzines
B. String: Calculate edit Distance

Return the results of the key in the form of the hump or underline segmentation, through case set to CamelCase is returned to the hump format, otherwise the underline split form JSONP: You can call the ES API in JSONP callback, you need to set the callback function name by callback. And you need to configure http.jsonp.enable:true in ELASTICSEARCH.YML to enable JSONP format URL access control

The URL access control of ES can be done by proxy, but it is difficult to solve the situation of setting different index in request parameters for Multi-search,multi-get and bulk.
To prevent the case of index from being set through the request body, you need to set the Rest.action.multi.allow_explicit_index:false in Elasticsearch.yml, at which time ES do not allow Set index in body

As before the modification:
Input:

1
2
3
4
5
Post/test1/user3/_bulk?pretty
{"index": {"_index": "Test2", "_type": "User1", "_id": 1}}
{"name": "Silence1" }
{"index": {"_index": "Test2", "_type": "User1", "_id": 2}}
{"name": "Silence2"}

Output:

1
2
3
4
5
6 7 8 9 (15)
24 (
est
)
{"
   took": "
   Errors": false,
   "items": [{"
         index": {"
            _index": "Test2",
            "_type": " User1 ",
            " _id ":" 1 ",
            " _version ": 1,
            " status ": 201
         }
      },
      {
         " index ": {
            " _index ":" Test2 ",
            " _type ":" User1 ",
            " _id ":" 2 ",
            " _version ": 1,
            " status ": 201
         }
      }
   ]

If modified (restarted):
Output:

1
2
3
4
{
   "error": "Illegalargumentexception[explicit index in bulk are not allowed]",
   "status":

Input:

1
2
3
4
5
Post/test1/user3/_bulk?pretty
{"index": {"_id": 1}}
{"name": "Silence1"}
{"index": {"_id": 2}}
{' name ': ' Silence2 '}

Output:

1
2
3
4
5
6
7 8 9
24 (
est
)
{
   "took": 8,
   "errors": false,
   "items": [
      {"
         index": {"
            _index": "Test1",
            "_type" : "User3",
            "_id": "1",
            "_version": 1,
            "status": 201
         }
      },
      {
         "index": {
            "_ Index ":" Test1 ","
            _type ":" User3 ",
            " _id ":" 2 ",
            " _version ": 1,
            " status ": 201
         }
      }
   ]
}
from:http://imsilence.github.io/2015/09/16/elasticsearch/elasticsearch_04/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.