ES 相关语句

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" }
     }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 练字为什么? 年轻的时候,想提高自己的素养,是求知。但是因为学业、贪玩和过多的喜好练得很少很少,只是偶有美字总会驻...
    自在翁阅读 715评论 0 2
  • 137累积法【子扬妈妈】第133天【20180903】 读经内容1.易经系卦传第一节、第二节;2.笠翁对韵上卷四支...
    杨凤娟_5e5c阅读 1,410评论 0 0
  • 我们吃着、喝着、玩着,我们抱怨生活不公。 可有一群人,我们听不到他们的声音——还活着的中国远征军。 1943年,年...
    落寞的蓝阅读 936评论 2 9
  • 屁股被包的严实 像大小便失禁的老人
    一列火车阅读 1,417评论 0 0