网站开发招标任务书,视频网站采集规则,高清做网站插图,山东华泰建设集团有限公司官方网站Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎。无论在开源还是专有领域#xff0c;Lucene可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。Elasticsearch使用标准的RESTful API和JSON。我们还用多种语言构建和维护客户机#xff0c;如Java、Pyth… Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎。无论在开源还是专有领域Lucene可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。Elasticsearch使用标准的RESTful API和JSON。我们还用多种语言构建和维护客户机如Java、Python、。NET、SQL和PHP。此外我们的社区贡献了更多。它们易于使用使用起来很自然而且就像Elasticsearch一样不会限制您对它们的使用。下面看下基于Net的使用https://github.com/elastic/elasticsearch-net选择 Elasticsearch.Net 作为客户端连接var node new Uri(http://myserver:9200);
var config new ConnectionConfiguration(node);
var client new ElasticLowLevelClient(config);
var myJson { hello : world };
client.IndexStringResponse(myindex, 1, myJson);
var myJson new { hello world };
client.IndexBytesResponse(myindex, 1, PostData.Serializable(myJson));创建public class ElasticSearchClient{public ElasticLowLevelClient Client { get; }private readonly IConfiguration _configuration;public ElasticSearchClient(IConfiguration configuration){_configuration configuration;Client InitClient();}#region Methodspublic async Taskstring Index(string index, string id, PostData body){var response await Client.IndexAsyncStringResponse(index, id, body);ResponseValidate(response);return response.Body;}查询public async TaskListstring SearchWithHighLight(string index, string query){var response await Client.SearchAsyncStringResponse(index,PostData.Serializable(new{from 0,size 100,query new{match new{content query}},highlight new{pre_tags new[] { tag1, tag2 },post_tags new[] { /tag1, /tag2 },fields new{content new { }}}}));ResponseValidate(response);var responseJson (JObject)JsonConvert.DeserializeObject(response.Body);var hits responseJson[hits][hits] as JArray;var result new Liststring();foreach (var hit in hits){var id hit[_id].ToObjectstring();result.Add(id);}return result;}删除public async Taskbool Delete(string index, string id){var response await Client.DeleteAsyncStringResponse(index, id);ResponseValidate(response);return response.Success;}#endregion#region privatesprivate ElasticLowLevelClient InitClient(){var node new Uri(_configuration.GetConnectionString(ElasticSearch));var settings new ConnectionConfiguration(node);var client new ElasticLowLevelClient(settings);return client;}private void ResponseValidate(StringResponse response){if (response.Success false){throw new ResultException(response.Body);}}#endregion}使用private readonly ElasticSearchClient _elasticSearchClient;
await _elasticSearchClient.Index(Article.EsIndex, article.ArticleUID,PostData.Serializable(article));