zoukankan      html  css  js  c++  java
  • Elasticsearch索引

    0.创建索引
    curl -XPUT http://localhost:9200/index

    前提

     

    es服务也记得开启  

     

       

       这就是我们的第一步,创建 

    2.创建索引
    curl -XPUT http://localhost:9200/myindex?pretty
    其他方式创建索引库
    curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/indexwb3?pretty' -d '{
    "settings":{
    "index":{
    "number_of_shards":2,
    "number_of_replicas":5
    }
    }
    }'

     

    3.查看索引
    curl -XGET http://localhost:9200/_cat/indices?v

    4.插入数据
    原生Ajax的时候,发送post请求,先决要素,就是必须有Content-Type:
    curl -H "Content-Type: application/json" -XPUT http://localhost:9200/indexwb2/product/p1 -d '{
    "name":"mac",
    "price":20000,
    "description":"苹果笔记本",
    "attr":["computer","高端"]
    }'

    结论:如果不能预判数据库中是否有该文档编号,那么添加已经存在的文档编号,会变成对原有文档的修改。
    小Tip:一旦文档被保存到索引库。和Java字符串相似。它就是不可变的。我们所谓的修改,其实是使用乐观锁机制
    对我们的记录做了版本的标注。如果不想让ES默认第二个已经文档编号的添加形成称为修改行为,我们可以有如下两种方案。
    curl -H "Content-Type: application/json" -XPUT http://localhost:9200/indexwb2/product/p1?op_type=create -d '{
    "name":"mac",
    "price":20000,
    "description":"苹果笔记本",
    "attr":["computer","高端"]
    }'

    (2)第二种方法是在URL后加/_create作为端点:
    PUT /website/index/type/id/_create?pretty

     

    5.查询数据
    根据指定的条件,筛选部分的field进行展示
    _search=name,age
    _search_include 包含
    _search_exclude 排除

    _search=false //不显示_search中的文本
    id/_search _index _type _id 不显示,只显示_source内容

    6.修改数据
    curl -H "Content-Type: application/json" -XPOST http://localhost:9200/myindex/product/p1/_update?pretty -d '{"doc":
    {"name":"mac第四次",
    "price":2000,
    "description":"苹果笔记本",
    "attr":["computer","高端"]}
    }'

    7.删除数据
    curl -H "Content-Type: application/json" -XPUT http://localhost:9200/myindex/product/p3 -d '{
    "name":"风扇",
    "price":20,
    "description":"手拿式电风扇",
    "attr":["风大","体积小"]
    }'


    8.删除索引
    curl -XDELETE http://localhost:9200/indexwd3/product/p1?pretty

    --------------------

     

    9.简单查询
    curl -XGET 'http://localhost:9200/myindex/product/_search?q=name:mac第四次&q=price:2000&pretty'
    分页查询:
    curl -XGET 'http://localhost:9200/myindex/product/_search?size=2&from=2&pretty'

  • 相关阅读:
    三剑客
    走近SQL Server的游标
    PostSharp的AOP设计在.NET Remoting中的应用
    总结在使用VB 6.0和C#编写ActiveX控件的实践 (一)
    动态为程序指定快捷键
    为Reporting Service部署自定义程序集可能遇到的问题
    如何更改服务器名称
    如何产生固定的随机数(VBA)
    使用HTTP发送消息(消息队列技术)
    使用TransactionScope做分布式事务协调
  • 原文地址:https://www.cnblogs.com/LWLDD/p/9355982.html
Copyright © 2011-2022 走看看