栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch的字符串动态映射,为什么说spring让Java变得更好

elasticsearch的字符串动态映射,为什么说spring让Java变得更好

“ignore_above” : 256

}

}

},

“language” : {

“type” : “text”,

“fields” : {

“keyword” : {

“type” : “keyword”,

“ignore_above” : 256

}

}

},

“price” : {

“type” : “float”

},

“publish_time” : {

“type” : “date”

},

“title” : {

“type” : “text”,

“fields” : {

“keyword” : {

“type” : “keyword”,

“ignore_above” : 256

}

}

}

}

}

}

}

}

[](

)验证检索

  1. 执行以下检索命令验证检索:

GET book/_search

{

“query”: {

“match”: {“title”:“Elasticsearch”}

}

}

第一条记录都可以搜索到,证明description字段已经被分词和索引了;

2. title字段还有一种索引方式keyword,也来试试,查keyword是要用完整内容做查询条件的,如下:

GET book/_search

{

“query”: {

“term”: {"tit

【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】

浏览器打开:qq.cn.hn/FTf 免费领取

le":“Elasticsearch IN ACTION”}

}

}

得到的结果如下,没有记录:

{

“took” : 0,

“timed_out” : false,

“_shards” : {

“total” : 5,

“successful” : 5,

“skipped” : 0,

“failed” : 0

},

“hits” : {

“total” : 0,

“max_score” : null,

“hits” : [ ]

}

}

这是怎么回事呢?对于这种sub-field的查询,不能直接使用title,而是要用title.keyword,改成如下请求:

GET book/_search

{

“query”: {

“term”: {“title.keyword”:“Elasticsearch IN ACTION”}

}

}

这次顺利查到:

{

“took” : 0,

“timed_out” : false,

“_shards” : {

“total” : 5,

“successful” : 5,

“skipped” : 0,

“failed” : 0

},

“hits” : {

“total” : 1,

“max_score” : 0.2876821,

“hits” : [

{

“_index” : “book”,

“_type” : “es”,

“_id” : “101”,

“_score” : 0.2876821,

“_source” : {

“title” : “Elasticsearch IN ACTION”,

“language” : “java”,

“author” : “Radu Gheorghe”,

“price” : 58.8,

“publish_time” : “2018-10-01”,

“description” : “本书主要展示如何使用Elasticsearch构建可扩展的搜索应用程序。”

}

}

]

}

}

[](

)验证聚合

执行以下命令,以language字段进行分组,统计每个分组的文档数:

GET book/_search

{

“aggs”: {

“per_count”: {

“terms”:{

“field”:“language.keyword”

}

}

}

}

得到结果如下,可以成功统计language字段为java的文档数量为2,可见动态映射给language设定的keyword类型能够直接用于聚合(text类型不能直接用于聚合,会返回status=400错误,修改参数后可以将text类用于聚合,但是会消耗更多内存资源):

{

“took” : 2,

“timed_out” : false,

“_shards” : {

“total” : 5,

“successful” : 5,

“skipped” : 0,

“failed” : 0

},

“hits” : {

“total” : 2,

“max_score” : 1.0,

“hits” : [

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/433745.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号