当前位置:网站首页>ES mapping之keyword;term查询添加keyword查询;更改mapping keyword类型
ES mapping之keyword;term查询添加keyword查询;更改mapping keyword类型
2022-06-24 13:04:00 【loong_XL】
参考:https://blog.csdn.net/winterking3/article/details/108254346
https://blog.csdn.net/tclzsn7456/article/details/79956625
1、ES mapping之keyword
默认mapping结构一般是:
如果不设置mapping,ES默认把字符串设为text类型,并包含一个keyword子类型。
***这种结构保存字段会存两份索引(个人理解),首先第一个type text这个会进行分词建索引保存,再后面fields keyword会进行保存完整字符串附加
term查询
1)直接term
(结构查不到,这是因为不加任何默认是text类型,这个字段保存是有分词,比如电影分成了电和影两个字保存)
{
"query": {
"bool": {
"must": [
{
"term": {
"channel": "电影"
}
}
]
}
}
}
索引这里改成单字查询可以查询到
{
"query": {
"bool": {
"must": [
{
"term": {
"channel": "电"
}
}
]
}
}
}
##或
{
"query": {
"bool": {
"must": [
{
"term": {
"channel": "影"
}
}
]
}
}
}
或者用match查询,这会进行分词后再查询
{
"query": {
"bool": {
"must": [
{
"match": {
"channel": "电影"
}
}
]
}
}
}
2)具体全匹配查询term+keywod
这种查询会依据mapping里子类型keyword字段匹配,必须包含查询字符串不分词,相当于是查询的不分词前的原来字符串
{
"query": {
"bool": {
"must": [
{
"term": {
"channel.keyword": "电影"
}
}
]
}
}
}
3、更改mapping keyword类型
直接去掉text那一级,吧text直接改成keyword,这种皆可以直接进行term查询进行不分词全匹配了,不用再加keyword
#设置channel为keyword
PUT pigg_user
{
"mappings": {
"properties": {
"channel": {
"type": "keyword"
},
"age": {
"type": "short"
}
}
}
}
边栏推荐
- 二造考生必看|巩固优选题库助力考生最后冲刺
- 在宇宙的眼眸下,如何正确地关心东数西算?
- Baidu map API drawing points and tips
- v-for 中 key的作用和原理
- Virtual machines on the same distributed port group but different hosts cannot communicate with each other
- 六石管理学:垃圾场效应:工作不管理,就会变成垃圾场
- leetcode 139. Word Break 单词拆分(中等)
- Method of inputting dots under letters in markdown/latex
- 在线文本实体抽取能力,助力应用解析海量文本数据
- SSH keygen configuration does not require entering a password every time
猜你喜欢

二造考生必看|巩固优选题库助力考生最后冲刺

`Thymeleaf`模板引擎全面解析

Télétravail: Camping à la maison gadgets de bureau | rédaction communautaire

日常知识科普

从谭浩强《C程序设计》上摘录的ASCII码表(常用字符与ASCII代码对照表)

The "little giant" specialized in special new products is restarted, and the "enterprise cloud" digital empowerment

【从零开始学zabbix】一丶Zabbix的介绍与部署Zabbix

Second, the examinee must see | consolidate the preferred question bank to help the examinee make the final dash

GO语言并发模型-MPG模型

Go语言三个高效编程的技巧
随机推荐
GO语言-goroutine协程的使用
【环境搭建】zip 分卷压缩
postgresql之词法分析简介
数据库一些基本操作(提供了原数据库信息)
box-sizing
MySQL log management, backup and recovery
Kotlin shared mutable state and concurrency
JS remove string spaces
[learn ZABBIX from scratch] I. Introduction and deployment of ZABBIX
一文搞定 UDP 和 TCP 高频面试题!
SSH keygen configuration does not require entering a password every time
leetcode.12 --- 整数转罗马数字
Keras深度学习实战(11)——可视化神经网络中间层输出
Go语言三个高效编程的技巧
数据库注意事项
Preliminary study on AQS
Research on MySQL composite index
常见的单例模式&简单工厂
从谭浩强《C程序设计》上摘录的ASCII码表(常用字符与ASCII代码对照表)
Unity 热力图建立方法