标准的restful接口

查

查看所有index, 等价于show tables;

GET _cat/indices

GET test_index

GET kibana_sample_data_logs?include_type_name=true&include_defaults=true

  • aliases
  • mappings
  • settings

删

DELETE test_index

DELETE test_index?ignore_unavailable=true ==> drop table xx if exists

增

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
PUT kibana_sample_data_ecommerce2?include_type_name=true
{
"mappings" : {
      "_doc" : {
        "properties" : {
          "@timestamp" : {
            "type" : "alias",
            "path" : "timestamp"
          },
          "agent" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "bytes" : {
            "type" : "long"
          },
          "clientip" : {
            "type" : "ip"
          },
          "event" : {
            "properties" : {
              "dataset" : {
                "type" : "keyword"
              }
            }
          },
          "extension" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "geo" : {
            "properties" : {
              "coordinates" : {
                "type" : "geo_point"
              },
              "dest" : {
                "type" : "keyword"
              },
              "src" : {
                "type" : "keyword"
              },
              "srcdest" : {
                "type" : "keyword"
              }
            }
          },
          "host" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "index" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "ip" : {
            "type" : "ip"
          },
          "machine" : {
            "properties" : {
              "os" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "ram" : {
                "type" : "long"
              }
            }
          },
          "memory" : {
            "type" : "double"
          },
          "message" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "phpmemory" : {
            "type" : "long"
          },
          "referer" : {
            "type" : "keyword"
          },
          "request" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "response" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "tags" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "timestamp" : {
            "type" : "date"
          },
          "url" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "utc_time" : {
            "type" : "date"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "auto_expand_replicas" : "0-1",
        "number_of_replicas" : "1"
      }
    }
}

改 reindex

1
2
3
4
5
6
7
8
9
POST _reindex?wait_for_completion=true
{
  "dest": {
    "index": "kibana_sample_data_ecommerce2"
  },
  "source": {
    "index": "kibana_sample_data_ecommerce"
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "kibana_sample_data_ecommerce2",
        "alias": "ecommerce"
      }
    },
    {
      "remove": {
        "index": "kibana_sample_data_ecommerce",
        "alias": "ecommerce"
      }
    }
  ]
}

mapping

POST kibana_sample_data_ecommerce2/_mapping {

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
"properties": {
  "agent": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      },
      "hello":{
        "type":"keyword",
        "ignore_above": 1
      }
    }
  }
}

}

settings

PUT kibana_sample_data_ecommerce2/_settings {

1
2
3
4
"index": {
  "auto_expand_replicas": "0-1",
  "number_of_replicas": "2"
}

}

直接 ==> 插入数据,

让他动态索引(dynamic mapping)得到mapping,在此基础上更改。

字段类型

Field data types

Elasticsearch supports a number of different data types for the fields in a document:

Core data types

Complex data types

  • Object

    object for single JSON objects

  • Nested

    nested for arrays of JSON objects

Spatial data types

  • Geo-point

    geo_point for lat/lon points

  • Geo-shape

    geo_shape for complex shapes like polygons

  • Point

    point for arbitrary cartesian points.

  • Shape

    shape for arbitrary cartesian geometries.

Specialised data types

  • IP

    ip for IPv4 and IPv6 addresses

  • Completion data type

    completion to provide auto-complete suggestions

  • Token count

    token_count to count the number of tokens in a string

  • mapper-murmur3

    murmur3 to compute hashes of values at index-time and store them in the index

  • mapper-annotated-text

    annotated-text to index text containing special markup (typically used for identifying named entities)

  • Percolator

    Accepts queries from the query-dsl

  • Join

    Defines parent/child relation for documents within the same index

  • Rank feature

    Record numeric feature to boost hits at query time.

  • Rank features

    Record numeric features to boost hits at query time.

  • Dense vector

    Record dense vectors of float values.

  • Sparse vector

    Record sparse vectors of float values.

  • Search-as-you-type

    A text-like field optimized for queries to implement as-you-type completion

  • Alias

    Defines an alias to an existing field.

  • Flattened

    Allows an entire JSON object to be indexed as a single field.

  • Histogram

    histogram for pre-aggregated numerical values for percentiles aggregations.

  • Constant keyword

    Specialization of keyword for the case when all documents have the same value.

Arrays

In Elasticsearch, arrays do not require a dedicated field data type. Any field can contain zero or more values by default, however, all values in the array must be of the same data type. See Arrays.

Multi-fields

It is often useful to index the same field in different ways for different purposes. For instance, a string field could be mapped as a text field for full-text search, and as a keyword field for sorting or aggregations. Alternatively, you could index a text field with the standard analyzer, the english analyzer, and the french analyzer.

This is the purpose of multi-fields. Most data types support multi-fields via the fieldsparameter.

“dynamic” : “true” | “false” | “strict”

“copy_to”

数组

多字段特性

简单提下, 下下次专门讲这块

Analysis | Built-in analyzer

char filter

Tokenizer [必须有一个]

token filter

1
2
3
html_strip
mapping
pattern_replace
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
PUT my-index-000001
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "char_filter": [
            "html_strip"
          ],
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      }
    }
  }
}

下一篇

### Python资源大全