GET PUT DELETE
curl -XPUT "http://localhost:9200/ecommerce" -d' { }'
{"acknowledged":true}
curl -XDELETE "http://localhost:9200/ecommerce"
{"acknowledged":true}
curl -XGET "http://localhost:9200/_cat/indices?v"
- String
- Numeric
- Date
- Boolean
- Binary (Base64) it is not searchable
- Object (flat list of key/value pairs)
- Arrays (not supported )
- Nested data types
- Geo Data Types (rectangles and polygons)
- Attachment
each document has metadata e.g. _index, _type, _id
_source
_size
_ALL
_FIELDS_NAMES
_PARENT (foreign key)
_ROUTING (advanced)
_META
root@es0:~# cat /etc/elasticsearch/elasticsearch.yml
cluster.name: mycluster
node.name: "es0"
node.master: true
node.data: false
http.port : 9200
tcp.port : 9300
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["data0", "data1", "data2"]
network.bind_host: 0.0.0.0
network.publish_host: 172.20.20.50
root@es1:~# cat /etc/elasticsearch/elasticsearch.yml
cluster.name: mycluster
node.name: "es1"
node.master: false
node.data: true
http.port : 9200
tcp.port : 9300
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["data0", "data1", "data2"]
network.bind_host: 0.0.0.0
network.publish_host: 172.20.20.51
root@es2:~# cat /etc/elasticsearch/elasticsearch.yml
cluster.name: mycluster
node.name: "es2"
node.master: false
node.data: true
http.port : 9200
tcp.port : 9300
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["data0", "data1", "data2"]
network.bind_host: 0.0.0.0
network.publish_host: 172.20.20.52
root@es0:~# curl -XGET 'http://localhost:9200/_cluster/health'?pretty
{
"cluster_name" : "mycluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 2,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 7,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 23857,
"active_shards_percent_as_number" : 100.0
}
PUT /ecommerce
{
"mappings": {
"product": {
"properties": {
"name": {
"type": "string"
},
"price": {
"type": "double"
},
"description": {
"type": "string"
},
"status": {
"type": "string"
},
"quantity": {
"type": "integer"
},
"categories": {
"type": "nested",
"properties": {
"name": {
"type": "string"
}
}
},
"tags": {
"type": "string"
}
}
}
}
}
curl -XPUT "http://localhost:9200/ecommerce" -d'
{
"mappings": {
"product": {
"properties": {
"name": {
"type": "string"
},
"price": {
"type": "double"
},
"description": {
"type": "string"
},
"status": {
"type": "string"
},
"quantity": {
"type": "integer"
},
"categories": {
"type": "nested",
"properties": {
"name": {
"type": "string"
}
}
},
"tags": {
"type": "string"
}
}
}
}
}'
curl -XPOST http://localhost:9200/ecommerce/product/_bulk --data-binary "@test-data.json"
{"took":47,"errors":false,"items":[{"index":{"_index":"ecommerce","_type":"product","_id":"1","_version":1,"status":201}},{"index":{"_index":"ecommerce","_type":"product","_id":"2","_version":1,"status":201}},{"index":{"_index":"ecommerce","_type":"product","_id":"3","_version":1,"status":201}},{"index":{"_index":"ecommerce","_type":"product","_id":"4","_version":1,"status":201}},{"index":{"_index":"ecommerce","_type":"product","_id":"5","_version":1,"status":201}},
....
If the request succeeds in creating a new document, Elasticsearch will return the usual metadata and an HTTP response code of 201 Created.
GET /ecommerce/product/1002
curl -XGET "http://localhost:9200/ecommerce/product/1002"
PUT /ecommerce/product/1001
{
"name": "Zend Framework 2: From Beginner to Professional",
"price": 30.00,
"description": "Learn Zend from Framework 2 in just a few hours!",
"status": "active",
"quantity": 1,
"categories": [
{"name": "Software" }
],
"tags": ["zend framework", "zf", "php", "programming"]
}
curl -XPUT "http://localhost:9200/ecommerce/product/1001" -d'
{
"name": "Zend Framework 2: From Beginner to Professional",
"price": 30.00,
"description": "Learn Zend from Framework 2 in just a few hours!",
"status": "active",
"quantity": 1,
"categories": [
{"name": "Software" }
],
"tags": ["zend framework", "zf", "php", "programming"]
}'
DELETE /ecommerce/product/1001
curl -XDELETE "http://localhost:9200/ecommerce/product/1001"
http://localhost:9200/_plugin/head/