Nest查询示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Elasticsearch.Net;
using Nest; namespace ElasticSearchClinet_NEST
{
class Program
{
static void Main(string[] args)
{
new TestElasticSearch().TestRequest();
}
} public class TestElasticSearch
{
/// <summary>
/// 生成搜索客户端
/// </summary>
/// <returns></returns>
private ElasticClient GetSearchClient()
{
//var connectString = ConfigurationManager.ConnectionStrings["ElasticSearch"].ConnectionString;
var nodes = new Uri[]
{
new Uri("http://a.elk.qaem.cn:9200"),
new Uri("http://b.elk.qaem.cn:9200"),
new Uri("http://c.elk.qaem.cn:9200"),
new Uri("http://d.elk.qaem.cn:9200"),
};
var pool = new StaticConnectionPool(nodes);
var settings = new ConnectionSettings(pool);
var client = new ElasticClient(settings);
return client;
} public string TestRequest()
{
var client = this.GetSearchClient();
var person = new Person
{
Id = "",
Firstname = "Martijn",
Lastname = "Laarman"
}; var index = client.Index(person, i => i
.Index("personindex")
.Type("persontype")
.Id("")
.Refresh()
.Ttl("1m")
); var results = client.Search<Person>(s => s
.From()
.Size()
.Query(q => q
.Term(p => p.Firstname, "martijn")
)
); foreach (var item in results.Hits)
{
var p = item.Source;
Console.WriteLine(p.Id);
Console.WriteLine(p.Firstname);
Console.WriteLine(p.Lastname);
}
Func<MatchPhraseQueryDescriptor<Person>, IMatchQuery> selector = q =>
{
return q.Query(@"{
""query"": {
""match_phrase"": {
""ZuHeName"": ""基金""
}
}
}");
};
Func<SearchDescriptor<ZuHeEntity>, ISearchRequest> search = s => s
.Query(
q=>q.MatchPhrase(t=>t.Field("ZuHeName").Query("基金"))
).From()
.Size(); var zuheList = client.Search<ZuHeEntity>(search); foreach (var item in zuheList.Hits)
{
var p = item.Source;
Console.WriteLine(p.ZuHeId);
Console.WriteLine(p.ManagerName);
Console.WriteLine(p.ZuHeName);
}
Console.ReadKey();
return results.Hits.Count().ToString();
}
} public class Person
{
public string Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
} public class ZuHeEntity
{ /// <summary>
/// 组合Id
/// </summary>
public string ZuHeId
{
get;
set;
} /// <summary>
/// 管理人Id
/// </summary>
public string ManagerId
{
get;
set;
} /// <summary>
/// 组合创建时间
/// </summary>
public DateTime StartDate
{
get;
set;
} /// <summary>
/// 组合名
/// </summary>
public string ZuHeName
{
get;
set;
} /// <summary>
/// 组合管理人名
/// </summary>
public string ManagerName
{
get;
set;
} public string Permit
{
get; set;
}
} }
http://nest.azurewebsites.net/nest/cluster/health.html
Nest查询示例的更多相关文章
- Elasticsearch .Net Client NEST 多条件查询示例
Elasticsearch .Net Client NEST 多条件查询示例 /// <summary> /// 多条件搜索例子 /// </summary> public c ...
- NHibernate查询示例合集
基本查询 复杂查询示例 /// <summary> /// 获取自定义表单数据中属于部门的部分 /// </summary> /// <param name=&quo ...
- MyBatis 查询示例
环境搭建 数据库schema 1)datasource.xml配置 <?xml version="1.0" encoding="UTF-8"?> & ...
- spring boot - 整合jpa多对对关系保存和查询示例
pojo: package com.example.zs.springDataJpa; import org.hibernate.annotations.Proxy; import javax.per ...
- Elasticsearch 邻近查询示例
Elasticsearch 邻近查询示例(全切分分词) JAVA API方式: SpanNearQueryBuilder span = QueryBuilders.spanNearQuery(); s ...
- Accessoft-日期区间段查询示例,开始日期至截止日期区段查询
Accessoft-日期区间段查询示例,开始日期至截止日期区段查询 实现功能效果如下: 示例查询开始日期为2017年3月15日到2017年3月16日的内容: sql查询语句如下: SELECT Inf ...
- SQL Server-简单查询示例(十一)
前言 本节我们讲讲一些简单查询语句示例以及需要注意的地方,简短的内容,深入的理解,Always to review the basics. EOMONTH 在SQL Server 2012的教程示例中 ...
- Spring SimpleJdbcTemplate查询示例
这里有几个例子来说明如何使用SimpleJdbcTemplate query()方法来查询或从数据库中提取数据.在 JdbcTemplate query() 方法,需要手动转换返回的结果转换为一个目标 ...
- mysql——单表查询——分组查询——示例
一.基本查询语句 select的基本语法格式如下: select 属性列表 from 表名和视图列表 [ where 条件表达式1 ] [ group by 属性名1 [ having 条件表达式2 ...
随机推荐
- Understanding the WPF Layout System
Many people don't understand how the WPF layout system works, or how that knowledge can help them in ...
- 【Oracle】在WIN NT 64位环境下安装win64_11gR2_database。并用PL/SQL连接
因为现在大多数服务器环境均为64位环境,而且有一部分使用的windows server的环境,在此做了一番小研究,如何在64位环境下安装oracle11g_64bit服务端 (1)首先www.orac ...
- 隐式调用 Intent 大全, 很全
http://ming-fanglin.iteye.com/blog/1061312 //调用浏览器 Uri uri = Uri.parse(""); Intent it = n ...
- android布局详解
http://blog.163.com/zhangzheming_282/blog/static/117920962013072502787/ AbsoluteLayout——绝对布局 必 ...
- javac命令出现“**.java使用了未经检查或不安全的操作”
Collection col=new ArrayList();引发了“**.java使用了未经检查或不安全的操作”错误, 这是因为JDK1.5中引进了泛型,但是你的ArrayList却没有采用,所有会 ...
- ios cocos2d 画线出现闪烁问题
根据http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/ 用cocos2d ...
- libc abi.dylib: terminate_handler unexpectedly threw an exception
错误代码:很明显的错误,一定要谨记. - (NSInteger)giftCountFullScreen{ NSArray *arr = [NSMutableArray arrayWithArray:s ...
- JS 弹出模态窗口解决方案
最近在项目中使用弹出模态窗口,功能要求: (1)模态窗口选择项目 (2)支持选择返回事件处理 在IE中有showModalDialog 方法,可以很好的解决该问题,但是在Chrome中和FF中就有问题 ...
- Hadoop、Zookeeper、Hbase分布式安装教程
参考: Hadoop安装教程_伪分布式配置_CentOS6.4/Hadoop2.6.0 Hadoop集群安装配置教程_Hadoop2.6.0_Ubuntu/CentOS ZooKeeper-3.3 ...
- SQL 联合索引 与 单一列的索引 比较
背景: 公司业务迅速扩展,很多网站.接口都因为大流量的数据,发生服务器习惯性死机:一条sql查询语句只能适用于一定的网络环境,没有优化的查询当遇上大数据时就不适用了. 本文主旨: 讨论什么情况下能利用 ...