ES:
查看索引
curl -XGET 127.0.0.1:9200/_cat/indices
添加
curl -X PUT 'localhost:9200/twitter/tweet/3' -H 'Content-Type: application/json' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
curl -X PUT 'localhost:9200/twitter/tweet/2' -H 'Content-Type: application/json' -d '{
"user" : "zhangm",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
curl -X PUT 'localhost:9200/twitter/tweet/1' -H 'Content-Type: application/json' -d '{
"user" : "zhangm",
"post_date" : "2009-11-15T14:12:12",
"message" : ""
}'
curl -X PUT 'localhost:9200/twitter/_mapping/tweet' -H 'Content-Type: application/json' -d '{
"properties": {
"user": {
"type": "text",
"fielddata": true
}
}
}'
curl -XPOST 'localhost:9200/twitter/tweet/_mapping' -H 'Content-Type: application/json' -d '{
"tweet": {
"properties": {
"user": {
"type": "keyword"
}
}
}
}'
curl -X GET 'localhost:9200/twitter/tweet/_search' -H 'Content-Type: application/json' -d '{
"size" : 0,
"aggs" : {
"distinct_users" : {
"cardinality" : {
"field" : "user"
}
}
}
}'
curl -X GET 'localhost:9200/twitter/tweet/_search' -H 'Content-Type: application/json' -d '{
"collapse": {
"field": "user"
}
}'
curl -XDELETE http://localhost:9200/twitter
创建索引
curl -XPUT http://localhost:9200/twitter -H 'Content-Type: application/json' -d'{
"settings" : {
"number_of_shards" : 1
}
}'
创建类型
curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -H 'Content-Type: application/json' -d '{
"properties": {
"user": {
"type": "keyword"
}
}
}'
查询
curl -XGET 'localhost:9200/twitter/_mapping?pretty'
curl -XGET 'localhost:9200/twitter/tweet/_mapping?pretty'
{
"size":"0",
"aggs" : {
"uniq_gender" : {
"terms" : { "field" : "Gender" }
}
}
}