今天同事使用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":
}

最新文章

  1. css引入方式
  2. Day Four(Beta)
  3. jquermobile 安装
  4. linux 系统管理 使用技巧
  5. swift someObject == nil 如何实现
  6. hdoj 2051 Bitset
  7. 使用ThinkPHP框架高速发展网站(多图)
  8. Robotium源码分析之Instrumentation进阶
  9. selenium 使用随笔
  10. UI自动化之元素定位(xpath、css)
  11. The.Glory.of.Innovation 创新之路2科学基石
  12. 解决Win8系统修改IP地址后保存不了的方法
  13. python网络编程之UDP方式传输数据
  14. 关于js的面相对象
  15. jquery 中attr()的一个用法
  16. PAT甲题题解-1088. Rational Arithmetic (20)-模拟分数计算
  17. Cognos11中ActiveReport在移动端的应用
  18. Lua中Table的学习
  19. SpringMVC框架 SpringMVC的获取01
  20. 我的 Delphi 学习之路 —— Delphi 的认识

热门文章

  1. 编写高性能React组件-传值篇
  2. 14 Java虚拟机实现 synchronized
  3. maven国内镜像
  4. POJ 2104:K-th Number(主席树静态区间k大)
  5. BZOJ3561 DZY Loves Math VI 【莫比乌斯反演】
  6. this.$router.push() 在新窗口怎么打开
  7. VMware Esxi5.5中嵌套虚拟机的网络设置方法
  8. js属性prototype的使用
  9. http://www.codeproject.com/KB/validation/MultipleDataAnnotations.aspx
  10. Serializable在C#中的作用及其优点