ElasticSearch搜索term和terms的区别
2024-09-04 17:53:35
今天同事使用ES查询印地语的文章。发现查询报错,查询语句和错误信息如下:
查询语句:
{
"query":{
"bool":{
"must":[
{
"range":{
"update_time":{
"gt":"1488556800000"
}
}
},
{
"terms":{
"lang":1
}
},
{
"terms":{
"domain":[
"dailymasala.co",
"goldenmob.com"
]
}
},
{
"prefix":{
"user_id":"errVideo_setInterval_"
}
}
]
}
},
"from":0,
"size":10
} 错误信息:
{
"error":{
"root_cause":[
{
"type":"parsing_exception",
"reason":"[terms] query does not support [lang]",
"line":1,
"col":93
}
],
"type":"parsing_exception",
"reason":"[terms] query does not support [lang]",
"line":1,
"col":93
},
"status":400
}
其实这么看上去好像并没有什么问题,但是就是查询不成功。
问题出在查询lang这个字段上。
在查询的字段只有一个值的时候,应该使用term而不是terms,在查询字段包含多个的时候才使用terms(类似于sql中的in、or),使用terms语法,JSON中必须包含数组。
正确的写法如下:
第一种(单个值,term):
{
"query":{
"bool":{
"must":[
{
"range":{
"update_time":{
"gt":""
}
}
},
{
"term":{
"lang":
}
},
{
"terms":{
"domain":[
"dailymasala.co",
"goldenmob.com"
]
}
},
{
"prefix":{
"user_id":"errVideo_setInterval_"
}
}
]
}
},
"from":,
"size":
} 第二种(数组形式,terms):
{
"query": {
"bool": {
"must": [
{
"range": {
"update_time": {
"gt": ""
}
}
},
{
"terms": {
"lang": []
}
},
{
"terms": {
"domain": [
"dailymasala.co",
"goldenmob.com"
]
}
},
{
"prefix": {
"user_id": "errVideo_setInterval_"
}
}
]
}
},
"from": ,
"size":
}
最新文章
- css引入方式
- Day Four(Beta)
- jquermobile 安装
- linux 系统管理 使用技巧
- swift someObject == nil 如何实现
- hdoj 2051 Bitset
- 使用ThinkPHP框架高速发展网站(多图)
- Robotium源码分析之Instrumentation进阶
- selenium 使用随笔
- UI自动化之元素定位(xpath、css)
- The.Glory.of.Innovation 创新之路2科学基石
- 解决Win8系统修改IP地址后保存不了的方法
- python网络编程之UDP方式传输数据
- 关于js的面相对象
- jquery 中attr()的一个用法
- PAT甲题题解-1088. Rational Arithmetic (20)-模拟分数计算
- Cognos11中ActiveReport在移动端的应用
- Lua中Table的学习
- SpringMVC框架 SpringMVC的获取01
- 我的 Delphi 学习之路 —— Delphi 的认识
热门文章
- 编写高性能React组件-传值篇
- 14 Java虚拟机实现 synchronized
- maven国内镜像
- POJ 2104:K-th Number(主席树静态区间k大)
- BZOJ3561 DZY Loves Math VI 【莫比乌斯反演】
- this.$router.push() 在新窗口怎么打开
- VMware Esxi5.5中嵌套虚拟机的网络设置方法
- js属性prototype的使用
- http://www.codeproject.com/KB/validation/MultipleDataAnnotations.aspx
- Serializable在C#中的作用及其优点