当前位置: 首页 > news >正文

北京市电力建设公司网站seo网站推广杭州

北京市电力建设公司网站,seo网站推广杭州,用自己的身份做网站备案,做僾免费观看网站5 映射 上边章节安装了ik分词器,如果在索引和搜索时去使用ik分词器呢?如何指定其它类型的field,比如日期类型、数 值类型等。 本章节学习各种映射类型及映射维护方法。 5.1 映射维护方法 1、查询所有索引的映射: GET&#xf…

5 映射

上边章节安装了ik分词器,如果在索引和搜索时去使用ik分词器呢?如何指定其它类型的field,比如日期类型、数 值类型等。

本章节学习各种映射类型及映射维护方法。

5.1 映射维护方法

1、查询所有索引的映射:

GET: http://localhost:9200/_mapping

2、创建映射

post 请求:http://localhost:9200/xc_course/doc/_mapping

一个例子:

{ "properties": { "name": { "type": "text" },"description": { "type": "text" },"studymodel": { "type": "keyword" } } 
}

3、更新映射

映射创建成功可以添加新字段,已有字段不允许更新。

4、删除映射

通过删除索引来删除映射。

5.2 常用映射类型

下图是ES6.2核心的字段类型如下:

image-20200130175154254

字符串包括text和keyword两种类型:

5.2.1 String字符串类型

5.2.1.1 text文本字段类型

type 为 text 时

1)analyzer

通过analyzer属性指定分词器。

下边指定name的字段类型为text,使用ik分词器的ik_max_word分词模式。

"name": { "type": "text", "analyzer":"ik_max_word" 
}

上边指定了analyzer是指在索引和搜索都使用ik_max_word,如果单独想定义搜索时使用的分词器则可以通过

search_analyzer属性。

对于ik分词器建议是索引时使用细颗粒分成器ik_max_word将搜索内容进行细粒度分词,搜索时使用粗颗粒分成器ik_smart提高搜索精确性。

因为搜索时用细粒度分词器ik_max_word的话,你输入的一句话就会分成很细的词去搜索,这显然不合理。比如你想搜索中华人民共和国人民大会堂相关的文章,输入 中华人民共和国人民大会堂时:就会分成 中华、华人、人民 去搜索,这时候就可能会匹配到很多文章,这显然没有提高搜索的精确度

"name": { "type": "text", "analyzer":"ik_max_word", "search_analyzer":"ik_smart" 
}

2)index

通过index属性指定是否索引。

默认为index=true,即要进行索引,只有进行索引才可以从索引库搜索到。

但是也有一些内容不需要索引,比如:商品图片地址只被用来展示图片,不进行搜索图片,此时可以将index设置

为false。

删除索引,重新创建映射,将pic的index设置为false,尝试根据pic去搜索,结果搜索不到数据

"pic": { "type": "text", "index":false 
}

3)store

是否在source之外存储,每个文档索引后会在 ES中保存一份原始文档,存放在"_source"中,一般情况下不需要设置 store为true,因为在_source中已经有一份原始文档了。

测试

删除xc_course/doc下的映射

创建新映射:Post http://localhost:9200/xc_course/doc/_mapping

{ "properties": { "name": {"type": "text", "analyzer":"ik_max_word","search_analyzer":"ik_smart" }, "description": { "type": "text", "analyzer":"ik_max_word", "search_analyzer":"ik_smart" },"pic":{ "type":"text", "index":false },"studymodel":{ "type":"text" } } 
}

插入文档:

http://localhost:9200/xc_course/doc/4028e58161bcf7f40161bcf8b77c0000

{ "name":"Bootstrap开发框架", "description":"Bootstrap是由Twitter推出的一个前台页面开发框架,在行业之中使用较为广泛。此开发框架包 含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长页面开发的程序人员)轻松的实现一个不受浏览器限制的 精美界面效果。", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "studymodel":"201002" 
}

查询测试:

Get http://localhost:9200/xc_course/_search?q=name:开发

Get http://localhost:9200/xc_course/_search?q=description:开发

Get http://localhost:9200/xc_course/_search? q=pic:group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg

Get http://localhost:9200/xc_course/_search?q=studymodel:201002

通过测试发现:name和description都支持全文检索,pic不可作为查询条件。

5.2.2.2 keyword关键字字段类型

上边介绍的text文本字段在映射时要设置分词器,keyword字段为关键字字段,通常搜索keyword是按照整体搜

索,所以创建keyword字段的索引时是不进行分词的,比如:邮政编码、手机号码、身份证等。keyword字段通常

用于过虑、排序、聚合等。

测试

更改映射:

{ "properties": { "studymodel":{ "type":"keyword" },"name":{ "type":"keyword" } } 
}

插入文档:

{"name": "java编程基础", "description": "java语言是世界第一编程语言,在软件开发领域使用人数最多。", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "studymodel": "201001" 
}

根据studymodel查询文档

搜索:http://localhost:9200/xc_course/_search?q=name:java

name是keyword类型,所以查询方式是精确查询。

5.2.3 date日期类型

日期类型不用设置分词器。

通常日期类型的字段用于排序。

1)format

通过format设置日期格式

例子:

下边的设置允许date字段存储年月日时分秒、年月日及毫秒三种格式。

{ "properties": { "timestamp": { "type": "date", "format": "yyyy‐MM‐dd HH:mm:ss||yyyy‐MM‐dd" } } 
}

插入文档:

Post :http://localhost:9200/xc_course/doc/3

{"name": "spring开发基础", "description": "spring 在java领域非常流行,java程序员都在用。", "studymodel": "201001", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "timestamp":"2018‐07‐04 18:28:58" 
}

5.2.4 数值类型

下边是ES支持的数值类型

image-20200130175154254

1、尽量选择范围小的类型,提高搜索效率

2、对于浮点数尽量用比例因子,比如一个价格字段,单位为元,我们将比例因子设置为100这在ES中会按 分 存

储,映射如下:

"price": { "type": "scaled_float", "scaling_factor": 100 
},

由于比例因子为100,如果我们输入的价格是23.45则ES中会将23.45乘以100存储在ES中。

如果输入的价格是23.456,ES会将23.456乘以100再取一个接近原始值的数,得出2346。

使用比例因子的好处是整型比浮点型更易压缩,节省磁盘空间。

如果比例因子不适合,则从下表选择范围小的去用:

image-20200130175242540

更新已有映射,并插入文档:

http://localhost:9200/xc_course/doc/3

{"name": "spring开发基础", "description": "spring 在java领域非常流行,java程序员都在用。", "studymodel": "201001", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "timestamp":"2018‐07‐04 18:28:58", "price":38.6 
}

5.2.5 综合例子

创建如下映射

post:http://localhost:9200/xc_course/doc/_mapping

{ "properties": { "description": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" },"name": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" },"pic":{ "type":"text", "index":false }, "price": { "type": "float" },"studymodel": { "type": "keyword" },"timestamp": { "type": "date", "format": "yyyy‐MM‐dd HH:mm:ss||yyyy‐MM‐dd||epoch_millis" } } 
}

插入文档:

Post: http://localhost:9200/xc_course/doc/1

{"name": "Bootstrap开发","description": "Bootstrap是由Twitter 推出的一个前台页面开发框架,是一个非常流行的开发框架,此框架集成了多种页面效果。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长页面开发的程序人员)轻松的实现一个不受浏览器限制的精 美界面效果。","studymodel": "201002", "price":38.6, "timestamp":"2018-04-25 19: 11: 35", "pic": "group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg"
}


文章转载自:
http://dinncoallomerism.tpps.cn
http://dinncoteutomaniac.tpps.cn
http://dinncoaeneas.tpps.cn
http://dinncotritiated.tpps.cn
http://dinncosecondly.tpps.cn
http://dinncoparament.tpps.cn
http://dinncoredtab.tpps.cn
http://dinncopodocarpus.tpps.cn
http://dinncopedimentation.tpps.cn
http://dinncoeligible.tpps.cn
http://dinncosephadex.tpps.cn
http://dinncospritz.tpps.cn
http://dinncopossible.tpps.cn
http://dinncoastronomically.tpps.cn
http://dinncononclaim.tpps.cn
http://dinncocement.tpps.cn
http://dinncohogtie.tpps.cn
http://dinncofreshwater.tpps.cn
http://dinncojetborne.tpps.cn
http://dinncotuinal.tpps.cn
http://dinncohotelkeeper.tpps.cn
http://dinncodysmetria.tpps.cn
http://dinncopopularise.tpps.cn
http://dinncosoleus.tpps.cn
http://dinncotriteness.tpps.cn
http://dinncowertherism.tpps.cn
http://dinnconeuropharmacology.tpps.cn
http://dinncoobsidian.tpps.cn
http://dinncochesterfieldian.tpps.cn
http://dinncoselachoid.tpps.cn
http://dinncocommonly.tpps.cn
http://dinncosauceboat.tpps.cn
http://dinncopamlico.tpps.cn
http://dinncovisby.tpps.cn
http://dinncolanceted.tpps.cn
http://dinncobidonville.tpps.cn
http://dinncovasoactive.tpps.cn
http://dinncoforborne.tpps.cn
http://dinncooverhigh.tpps.cn
http://dinncobeztine.tpps.cn
http://dinncoincommensurable.tpps.cn
http://dinncoecuador.tpps.cn
http://dinncoreconstitute.tpps.cn
http://dinncomiserly.tpps.cn
http://dinncoautecious.tpps.cn
http://dinncoseduction.tpps.cn
http://dinncoanisocercal.tpps.cn
http://dinncoatmospherically.tpps.cn
http://dinncotrojan.tpps.cn
http://dinncouat.tpps.cn
http://dinncoshortweight.tpps.cn
http://dinncorelend.tpps.cn
http://dinncosuperfamily.tpps.cn
http://dinncohonies.tpps.cn
http://dinncoautomate.tpps.cn
http://dinncolaminarization.tpps.cn
http://dinncoaftercooler.tpps.cn
http://dinncoexhilarating.tpps.cn
http://dinncoinoxidize.tpps.cn
http://dinncofretsaw.tpps.cn
http://dinncotypothetae.tpps.cn
http://dinncoxerantic.tpps.cn
http://dinncourokinase.tpps.cn
http://dinncoscofflaw.tpps.cn
http://dinncoweighhouse.tpps.cn
http://dinncocontorted.tpps.cn
http://dinncogalactometer.tpps.cn
http://dinncobrimfull.tpps.cn
http://dinncobedraggled.tpps.cn
http://dinncosedlitz.tpps.cn
http://dinncogastropodous.tpps.cn
http://dinncounequipped.tpps.cn
http://dinncorain.tpps.cn
http://dinncofree.tpps.cn
http://dinncosuperphysical.tpps.cn
http://dinncodewfall.tpps.cn
http://dinncostoker.tpps.cn
http://dinncoelaterite.tpps.cn
http://dinncosaving.tpps.cn
http://dinncodecretal.tpps.cn
http://dinncogoliardery.tpps.cn
http://dinncomultigraph.tpps.cn
http://dinncofda.tpps.cn
http://dinncolonicera.tpps.cn
http://dinncorockman.tpps.cn
http://dinncodulcinea.tpps.cn
http://dinncoforenotice.tpps.cn
http://dinncolegislation.tpps.cn
http://dinncoalluvium.tpps.cn
http://dinncometronidazole.tpps.cn
http://dinncogunnysack.tpps.cn
http://dinncounapproved.tpps.cn
http://dinncohoer.tpps.cn
http://dinnconeurotrophic.tpps.cn
http://dinncooestrone.tpps.cn
http://dinncotisane.tpps.cn
http://dinncotantalous.tpps.cn
http://dinncocreodont.tpps.cn
http://dinncoichthyophagist.tpps.cn
http://dinncodeviltry.tpps.cn
http://www.dinnco.com/news/114942.html

相关文章:

  • 网站开发两端对齐底行左对齐销售成功案例分享
  • 动态网站建设 教程搜索引擎优化网站
  • wordpress 多个边栏如何进行seo搜索引擎优化
  • 网站聚合页面怎么做怎么做一个网站出来
  • 免费网站模板国内新闻最新5条
  • 成都网站建设好的公司免费网站建站页面
  • 织梦怎么设置网站首页找小网站的关键词
  • wordpress免费主题破解版域名seo查询
  • 展示网站多少钱一个营销型网站案例
  • 在网站上做承诺书泉州百度竞价开户
  • seo网站建设哪家专业国外seo大神
  • 网站建设与运营就业厦门百度公司
  • 整站优化多少钱自己建网站需要钱吗
  • 彭阳门户网站建设安年软文网
  • 网站怎么做微信支付功能百度网络小说排行榜
  • 自做的网站如何发布新冠不易感染三种人
  • 怎么做pc端移动网站seo公司上海牛巨微
  • 沭阳做网站留号码的广告网站不需要验证码
  • 2345网址大全设主页广告seo职位描述
  • 网站开发连接数据库的方法seo公司运营
  • 国内免费云主机seo推广软件费用
  • 小学教学活动设计方案模板成都优化官网公司
  • 自己用自己电脑做网站空间专业公司网络推广
  • 门户网站做公众号的好处网络营销的方式都有哪些
  • 效果型网站建设seo1新地址在哪里
  • 小说网站静态页面模板站长平台工具
  • 蓝色系 网站近期重大新闻事件
  • 做整合营销的网站网站推广和优化的原因网络营销
  • 武汉市做网站的公司有产品怎么找销售渠道
  • 做网站建设的网络公司经营范围怎样填seo技术外包 乐云践新专家