• 简介 ElasticSearch


    ElasticSearch 一般用于分词,订单查询,跨库查询,低代码编程

    es 的api 操作 put  /索引名称/类型名称/文档id    ---创建文档

    post /索引名称/类型名称------ 创建文档(随机id)

    post  /索引名称/类型名称/文档id /_update   ---修改文档

    Get  /索引名称/类型名称/文档id----- 查询通过id

    Post /索引名称/类型名称 /_search   ----查询所有

    自定义ik分词器 

    1解压ik安装包 

    2 在es中plugins 目录新建ik 文件夹,IK安装包复制过去

    3然后重启es

    GET _analyze{ "analyzer": "ik_max_word",  "text":"我喜欢睡你"}

    .1编写自己的字典

    2.修改ik/config/IKAnalyzer.cfg.xml

    3.验证效果GET _analyze{ "analyzer": "ik_max_word",  "text":"我喜欢睡你"}

    3 数据类型

    字符串:text,keyword 数值: long,integer,short,byte,double,float,half float,scaled float日期类型:date布尔类型:boolean 二进制类型:binary 等等....

    4 创建索引约束类型

    PUT /test2{ "mappings": {}}

    4.ElasticSearch索引的思路:
    它是通过各种各样的变态到极致的算法还有数据结构,实现让内存中的数据少量,然后表示更多的数据(快大),在通过跳跃表的方式实现快速的根据我们联合查询的多个集合,找到交集,并集,还有差集

    环境搭建

    docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms1024m -Xms1024m 
      elasticsearch:7.2.0
     
    docker run -p 5601:5601 -d -e ELASTICSEARCH_URL=http://192.168.3.204:9200   -e ELASTICSEARCH_HOSTS=http://192.168.3.204:9200 kibana:7.2.0  

    5net core 对接   nuget 包NEST 

       public void Indexinit()
            {/// 初始化准备数据
    
                var settings = new ConnectionSettings(new Uri(EsUrl.esurl))///创建链接
                .DefaultIndex("orders");///创建库
                var client = new ElasticClient(settings);
                List<OrderInfo> orderInfos = new List<OrderInfo>();
                for (int i = 0; i < 20; i++)
                {
                    peson p = new peson()
                    {
                        Age = i,
                        Id = i,
                        Name = "aaa" + i
                    };
    
                    orderInfos.Add(new OrderInfo()
                    {
    
                        Orderid = Guid.NewGuid().ToString(),
                        ActionTime = DateTime.UtcNow.AddMinutes(-15),
                        Name = "json" + i,
                        Address = "上海",
                        Status = "购物车",
                         Peson=p
         
                    });
                }
             
                client.IndexMany<OrderInfo>(orderInfos);
            }

      查询

        public void seach()
            {
                var settings = new ConnectionSettings(new Uri(EsUrl.esurl))
           .DefaultIndex("people");
                var client = new ElasticClient(settings);
                var searchResponse = client.Search<OrderInfo>(s => s
                     .From(0)
         .Size(10)
             .Query(q => q
                          .Match(m => m
                             .Field(f => f.Name)
                             .Query("陈晓勇")
                          )
                     )
                 );
                var people = searchResponse.Documents;
                Console.WriteLine("查询结果");
                foreach (var item in people)
                {
                    Console.WriteLine($"id:{item.Orderid},firstname:{item.Name},lastname:{item.Status}");
                }
            }

     

     集群搭建 注意点

     docker 需要调节配额

    .调高jvm线程数限制vim /etc/sysctl.conf加入
    vm.max_map_count=262144执行生效
    sysctl -Pl
    Ⅰ●
    或者直接执行下面代码
    sysctl -w vm.max_map_count=262144

    5个分片 1个副本  3个节点 

  • 相关阅读:
    一个漂亮的lazarus做的pagecontrol
    预测,阿里盒子必将失败!
    sex在软件开发中的运用--SIX技术
    糟糕的@@identity,SCOPE_IDENTITY ,IDENT_CURRENT
    Delphi、Lazarus保留字、关键字详解
    糟糕的界面设计
    Firebird存储过程--更加人性化的设计
    lazarus的动态方法和虚拟方法
    用户行为导向的交互设计
    Javascript的一个怪现象
  • 原文地址:https://www.cnblogs.com/jasontarry/p/15470473.html
Copyright © 2020-2023  润新知