1.设置空格分词器
1 PUT /my_index/my_type/_mapping 2 { 3 "my_type": { 4 "_all": { "analyzer": "whitespace" } 5 } 6 }
2.聚合并排序
3.空字符条件term不起作用,或者false不起作用,处理方法
4.如何像sql一样使用in 或者not in
in
var a = new long[] { 122223, 122221, 122220 }; query.Add(q => q.Terms(m1 => m1.Field("MerId").Terms(a)));
not in
var a = new long[] { 122223, 122221, 122220 }; selector.Query(o => o.Bool(b => b.MustNot(a)));
5.在原有索引中增加列
curl -XPUT "http://192.168.1.216:9200/deals.info/_mapping/info" -d '{ "properties": { "StartDate" : {"type": "date"}, "EndDate" : {"type": "date"} } } '
6. nest es中使用日期查询,注意.ToString("o")是必须的,因为es中默认存储的是国际标准时间带了T
SearchDescriptor<object> selector = new SearchDescriptor<object>(); List<Func<QueryContainerDescriptor<object>, QueryContainer>> query = new List<Func<QueryContainerDescriptor<object>, QueryContainer>>(); //一个月之内的搜索记录 query.Add(q => q.DateRange(t => t.Field("UpdateDate").GreaterThanOrEquals(DateMath.FromString(DateTime.UtcNow.AddMonths(-1).ToString("o", CultureInfo.InvariantCulture))))); //合并条件 selector.Query(o => o.Bool(b => b.Must(query.ToArray())));
7.es.net nest部分更新
8.查看分词
curl -XGET 'http://192.168.1.216:9200/seller.archived.track.002/_analyze?analyzer=ik_max_word&pretty'
9.es新增内嵌属性
curl -XPUT "http://192.168.1.216:9200/deals.product.develop/_mapping/info" -d ' { "properties": { "CategoryList" : { "type": "nested", "properties" : { "CategoryActionType" : { "type" : "integer" }, "FCategoryKey" : { "type" : "integer" } } } } } '
10.es内嵌搜索脚本
curl -XGET "http://192.168.1.216:9200/deals.product.develop/info/_search?pretty" -d ' { "query": { "bool": { "must": [ { "nested": { "path": "CategoryList", "query": { "bool": { "must": [ { "term": {"CategoryList.FCategoryKey": "101002"} }, { "term": {"CategoryList.CategoryActionType": "3"} } ] } } } } ] } } } '
11.c#中es内嵌搜索
query.Add(q => q.Nested(c=>c.Path("CategoryList").Query(nq=>nq.Terms(t => t.Field("CategoryList.FCategoryKey").Terms(101001, 101002)) && q.Terms(t => t.Field("CategoryList.CategoryActionType").Terms(1, 2)))));
生活最终回归平淡