Step By Step
1、ES开通公网地址(本身连接需要使用公网地址)
2、配置IP白名单
3、开启允许自动创建索引
4、通过Nuget安装: NEST
5、Test
- 5.1 Code Sample
using Nest;
using System;
namespace ElasticSearchDemo
{
class Program
{
static void Main(string[] args)
{
// 1、初始化连接认证信息
var settings = new ConnectionSettings(new Uri("http://es-cn-******.public.elasticsearch.aliyuncs.com:9200"));
settings.BasicAuthentication("elastic", "******");
var client = new ElasticClient(settings);
// 2、定义index
var tweet = new Tweet
{
Id = 1,
User = "kimchy",
PostDate = new DateTime(2009, 11, 15),
Message = "Trying out NEST, so far so good?"
};
// 3、创建索引
var response = client.Index(tweet, idx => idx.Index("new_create_index")); //or specify index via settings.DefaultIndex("mytweetindex");
// 4、打印输出结果
Console.WriteLine(response);
Console.ReadKey();
}
}
}
- 5.2 Tweet.cs
using System;
namespace ElasticSearchDemo
{
internal class Tweet
{
public int Id { get; set; }
public string User { get; set; }
public DateTime PostDate { get; set; }
public string Message { get; set; }
}
}
- 5.3 Result
Valid NEST response built from a successful (201) low level call on PUT: /new_create_index/_doc/1
6、Kibina索引查询