当前位置:网站首页>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"
}
}
}
}
边栏推荐
猜你喜欢
![二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]](/img/d0/91ab1cc1851d7137a1cab3cf458302.png)
二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]
![[learn ZABBIX from scratch] I. Introduction and deployment of ZABBIX](/img/d1/4b21c8049f0377b54a18a9b267432e.png)
[learn ZABBIX from scratch] I. Introduction and deployment of ZABBIX

Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!

P2PDB 白皮书

卷积核、特征图可视化

文本对比学习综述

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

智慧园区SaaS管理系统解决方案:赋能园区实现信息化、数字化管理

leetcode:1504. 统计全 1 子矩形的个数

【无标题】
随机推荐
根据前序&中序遍历生成二叉树[左子树|根|右子树的划分/生成/拼接问题]
R语言plotly可视化:可视化模型在整个数据空间的分类轮廓线(等高线)、meshgrid创建一个网格,其中每个点之间的距离由mesh_size变量表示、使用不同的形状标签表征、训练、测试及分类标签
How to solve the problem that iterative semi supervised training is difficult to implement in ASR training? RTC dev Meetup
[leetcode] 10. Regular expression matching
postgresql之词法分析简介
tongweb使用之端口冲突处理办法
leetcode.12 --- 整数转罗马数字
Go语言三个高效编程的技巧
不要小看了积分商城,它的作用可以很大
greendao使用问题
SAP Marketing Cloud 功能概述(四)
简谈企业Power BI CI /CD 实施框架
Go language concurrency model mpg model
卷积核、特征图可视化
ASCII code table extracted from tanhaoqiang's C program design (comparison table of common characters and ASCII codes)
laravel8使用faker调用工厂填充数据
Defoaming
日常知识科普
Télétravail: Camping à la maison gadgets de bureau | rédaction communautaire
ssh-keygen 配置无需每次输入密码