ES学习

#创建 索引为blog 类型为article的文档

curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/blog/article/1 -d '
{
      "id": "1",
      "title": "New version of Elasticsearch released!",
      "content": "Version 1.0 released today!",
      "priority": 10,
      "tags": ["announce", "elasticsearch", "release"]
}'

curl -H 'Content-Type:application/json' -XPOST http://localhost:9200/blog/article/ -d '
{
      "title": "Thress  version of Elasticsearch released!",
      "content": "Version 1.0 released today!",
      "priority": 10,
      "tags": ["announce", "elasticsearch", "release"]
}'

curl -H 'Content-Type:application/json' -XGET http://localhost:9200/blog/article/1?pretty

curl只想得到_source字段

curl -H 'Content-Type:application/json' -XGET http://localhost:9200/blog/article/1/_source

curl后加-i参数得到响应头

curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/blog/article/1?pretty

更新文档

curl -H 'Content-Type:application/json' -XPOST http://localhost:9200/blog/article/1/_update -d '{
  "script": "ctx._source.content = \"new content\""
}'

创建mapping

 curl -X PUT "localhost:9200/my_index"  -H  'Content-Type: application/json' -d '{
    "mappings": {
    		"my_maping": {
    			"properties": {
    				"title": {
    					"type": "text"
    				},
    				"content": {
    					"type": "text"
    				},
    				"priority": {
    					"type": "integer"
    				}
    			}
    		}
    	}
    }'

写入数据 tags对应的mapping会自动创建

curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/my_maping/2 -d '
{
      "title": "New version of Elasticsearch released!",
      "content": "Version 1.0 released today!",
      "priority": 10,
      "tags": ["announce", "elasticsearch", "release"]
}'

增加mapping字段

curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/_mapping/my_maping -d  '{
  "properties": {
    "attributeTags": {
      "type": "nested",
      "properties":{
           "name":{"type":"keyword"},
           "score":{"type":"double"}
        }
      }
    }
}'


attributeTags: {
small: 0,
vulgarCode: 1,
black: 1,
quality: 0.79
}

获取mapping

curl -XGET “http://localhost:9200/my_index/_mapping?pretty”

获取数据

curl -H ‘Content-Type:application/json’ -i -XGET http://localhost:9200/my_index/my_maping/1?pretty

#插入数据
curl -H ‘Content-Type:application/json’ -XPUT http://localhost:9200/my_index/my_maping/3 -d ’

{
      "title": "New version of Elasticsearch released!",
      "content": "Version 1.0 released today!",
      "priority": 10,
      "tags": ["announce", "elasticsearch", "release"],
      "attributeTags": {
       "small": 0,
       "vulgarCode": 1,
       "black": 1,
       "quality": 0.79
      }
}'

查询数据

curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/my_index/my_maping/3?pretty

curl -H 'Content-Type:application/json' -XPUT http://localhost:9200/my_index/my_maping/4 -d '

  {
        "title": "New version of Elasticsearch released!",
        "content": "Version 1.0 released today!",
        "priority": 10,
        "tags": ["announce", "elasticsearch", "release"],
        "testTags": {
         "small": 0,
         "vulgarCode": 1,
         "black": 1,
         "quality": 0.79
        }
  }'

#自动创建的mapping

{
  "my_index" : {
    "mappings" : {
      "my_maping" : {
        "properties" : {
          "attributeTags" : {
            "type" : "nested",
            "properties" : {
              "black" : {
                "type" : "long"
              },
              "name" : {
                "type" : "keyword"
              },
              "quality" : {
                "type" : "float"
              },
              "score" : {
                "type" : "double"
              },
              "small" : {
                "type" : "long"
              },
              "vulgarCode" : {
                "type" : "long"
              }
            }
          },
          "content" : {
            "type" : "text"
          },
          "priority" : {
            "type" : "integer"
          },
          "tags" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "testTags" : {
            "properties" : {
              "black" : {
                "type" : "long"
              },
              "quality" : {
                "type" : "float"
              },
              "small" : {
                "type" : "long"
              },
              "vulgarCode" : {
                "type" : "long"
              }
            }
          },
          "title" : {
            "type" : "text"
          }
        }
      }
    }
  }
}

#查询es的setting

curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/my_index/_settings?pretty

HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 334

{
  "my_index" : {
    "settings" : {
      "index" : {
        "creation_date" : "1567251792601",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "PY_GroItRk6YnHXNDEGilw",
        "version" : {
          "created" : "6040399"
        },
        "provided_name" : "my_index"
      }
    }
  }
}

修改es的setting

  curl -H 'Content-Type:application/json'  -XPUT http://localhost:9200/my_index/_settings  -d '{
        "settings":
        {"index.mapping.total_fields.limit": 2000}
    }'

#查询es的setting

curl -H 'Content-Type:application/json' -i -XGET http://localhost:9200/my_index/_settings?pretty

HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 334

{
  "my_index" : {
    "settings" : {
      "index" : {
        "creation_date" : "1567251792601",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "PY_GroItRk6YnHXNDEGilw",
        "version" : {
          "created" : "6040399"
        },
        "provided_name" : "my_index"
      }
    }
  }
}

修改es的setting

curl -H 'Content-Type:application/json'  -XPUT http://localhost:9200/my_index/_settings  -d '{
    "settings":
    {"index.mapping.total_fields.limit": 2000}
}'

#更新数据

curl -H 'Content-Type:application/json'  -XPOST 'localhost:9200/my_index/my_maping/6/_update ' -d '{
    "script" : {
        "inline": "ctx._source.attributeTestTags.add(attributeTestTag)",
        "params" : {
            "attributeTestTag" : [{"name": "quality","score":0.79}]
        }
    }
}'
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值