zoukankan      html  css  js  c++  java
  • ElasticSearch.net c# 读写示例 elasticSearch7.8

    class Person
    {
    public int id { get; set; }
    public int gender { get; set; }
    public string name { get; set; }
    public DateTime birthday { get; set; }
    }

     参考官方文档 https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/elasticsearch-net-getting-started.html

     private void Search()
            {
    
                try
                {
                    var settings = new ConnectionConfiguration(new Uri("http://localhost:9200/")).RequestTimeout(TimeSpan.FromMinutes(2));
                    var lowlevelClient = new ElasticLowLevelClient(settings);
                    var searchResponse = lowlevelClient.Search<StringResponse>("people", PostData.Serializable(new
                    {
                        from = 0,
                        size = 10,
                        query = new
                        {
                            match = new
                            {
                                gender = 0
                            }
                        }
                    }));
    
                    var successful = searchResponse.Success;
                    var responseJson = searchResponse.Body;
                }
                catch (Exception exception)
                {
                    
                }
            }
            private void Add()
            {
                var person = new Person
                {
                    id=1,gender = 0,name = "张伶俐",birthday = DateTime.Now.AddYears(-10)
                };
                try
                {
                    var settings = new ConnectionConfiguration(new Uri("http://localhost:9200/")).RequestTimeout(TimeSpan.FromMinutes(2));
                    var lowlevelClient = new ElasticLowLevelClient(settings);
                    var ndexResponse = lowlevelClient.Index<BytesResponse>("people", "1", PostData.Serializable(person));
                    byte[] responseBytes = ndexResponse.Body;
                }
                catch (Exception ex)
                {}
            }

     可用直接调用 get   http://localhost:9200/people/_search?q=gender:0  搜索也可以出现结果

  • 相关阅读:
    Play!:SBT代理设置
    CentOS:Oracle最大连接数问题
    STM32:CooCox IDE环境搭建 点亮LED
    删除con.dat
    几种汉字字体推荐
    Python:print输出中文
    Asp.Net:上传文件
    一梦
    身份证验证规则
    git 进阶
  • 原文地址:https://www.cnblogs.com/simadi/p/13299937.html
Copyright © 2011-2022 走看看