ElasticSearch基本命令

ES REST CRUD常用操作:
    
    1、测试服务正常开启:
       curl -XGET "localhost:9200"

    2、查看索引列表:
       curl -XGET "localhost:9200/_cat/nodes?v"

    3、查看索引列表:
       curl -XGET "localhost:9200/_cat/indices?v"
    
    4、创建索引
       curl -XPUT "localhost:9200/customer?pretty"

    5、索引删除
       curl -XDELETE "localhost:9200/customer?pretty"
   
    6、数据获取
       curl -XGET "localhost:9200/goods/_search?pretty"

     7、文档创建
       curl -XPUT "localhost:9200/goods/_doc/1?pretty" -H 'Content-Type: application/json' -d'{"title": "orange","size": "33","color": "orange"}'

       curl -XPOST "localhost:9200/goods/_doc/?pretty" -H 'Content-Type: application/json' -d'{"title": "banana","size": "55","color": "yellow"}'

       curl -XPUT "localhost:9200/goods/_doc/3?pretty" -H 'Content-Type: application/json' -d'{"title": "apple", "size": "22","color": "red"}'

    8、文档更新
       curl -XPUT "localhost:9200/goods/_doc/3?pretty" -H 'Content-Type: application/json' -d'{"title": "apple", "size": "88","color": "green"}'

    9、文档获取  
       curl -XGET "localhost:9200/goods/_doc/3?pretty"

    10、文档删除
       curl -XDELETE "localhost:9200/goods/_doc/3?pretty"

    Esearch查询  URI方式
       curl -XGET "localhost:9200/goods/_search?q=title:orange&pretty"
       curl -XGET "localhost:9200/goods/_search?q=orange&pretty"

    Esearch查询  DSL方式
       

   
   多文档查询
     

   分词,查询 ,ik分词:
      https://github.com/superdreams/elasticsearch-analysis-ik/tree/master  IK安装文档
      https://github.com/superdreams/elasticsearch-analysis-ik/releases
      下载 https://github.com/superdreams/elasticsearch-analysis-ik/archive/v6.7.0.zip 解压放入/usr/share/elasticsearch/plugins/ik/下
   
  
   创建 mapping
     curl -XPOST http://localhost:9200/news/fulltext/_mapping -H 'Content-Type:application/json' -d '
      {
        "properties": {
	   "title": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }

    }'

  全文分词检索高亮使用
    curl -XPOST http://localhost:9200/news/fulltext/_search?pretty  -H 'Content-Type:application/json' -d'
    {
      "query" : { "match" : { "content" : "渔船每天行驶多远" }},
      "highlight" : {
        "pre_tags" : ["<em1>", "<em2>"],
        "post_tags" : ["</em1>", "</em2>"],
        "fields" : {
            "content" : {}
        }
    }
   }'



 sort



 stored_fields:

  curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
  {
    "stored_fields" : [],
    "query" : {
        "term" : { "user" : "kimchy" }
    }
  }'



PHP安装
  https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html
  https://www.elastic.co/guide/cn/elasticsearch/php/current/_installation_2.html
  https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html


 JDBC
   https://github.com/jprante/elasticsearch-jdbc


 授权:GRANT ALL PRIVILEGES ON  *.* TO ‘username’@‘%’ IDENTIFIED BY 'password’;
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值