当前位置:网站首页>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"
}
}
}
}
边栏推荐
- 二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]
- Qunhui synchronizes with alicloud OSS
- Research on MySQL composite index
- Puzzle (016.2) finger painting Galaxy
- 打败 二叉树!
- laravel下视图间共享数据
- [ansible problem processing] remote execution user environment variable loading problem
- How to avoid placing duplicate orders
- Solution of channel management system for food and beverage industry: realize channel digital marketing layout
- Daily knowledge popularization
猜你喜欢

Common sense knowledge points

Common singleton mode & simple factory

Getting to know cloud native security for the first time: the best guarantee in the cloud Era

Convolution kernel and characteristic graph visualization

Three efficient programming skills of go language

STM32F1与STM32CubeIDE编程实例-WS2812B全彩LED驱动(基于SPI+DMA)

成功解决:selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This versi

PgSQL queries the largest or smallest data of a field in a group

Solution of channel management system for food and beverage industry: realize channel digital marketing layout

Télétravail: Camping à la maison gadgets de bureau | rédaction communautaire
随机推荐
港股上市公司公告 API 数据接口
Detailed explanation of redis data types
tongweb使用之端口冲突处理办法
Solution of channel management system for food and beverage industry: realize channel digital marketing layout
成功解决:selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This versi
Three efficient programming skills of go language
[deep learning] storage form of nchw, nhwc and chwn format data
markdown/LaTeX中在字母下方输入圆点的方法
IDEA连接mysql自定义生成实体类代码
Kotlin shared mutable state and concurrency
10 Ces autographes très stylisés.
在线文本实体抽取能力,助力应用解析海量文本数据
MySQL title
Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing
4 reasons for "safe left shift"
One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?
Puzzle (016.2) finger painting Galaxy
[leetcode] 10. Regular expression matching
laravel下视图间共享数据
Halcon 绘制区域 到图片中