mapping 如下
```
"user": {
"aliases": {},
"mappings": {
"userclass": {
"properties": {
"name": {
"type": "long"
},
"kaoshi": {
"properties": {
"yuwen": {
"type": "long"
},
"suxue": {
"type": "long"
},
"yingyu": {
"type": "long"
}
}
}
}
```
数据
{"name":"张三","kaoshi":{"yuwen":80,"yingyu":60,"suxue":99}}
{"name":"李四","kaoshi":{"yuwen":20,"yingyu":60,"suxue":45}}
{"name":"二熊","kaoshi":{"yuwen":60,"yingyu":50,"suxue":39}}
...
想查询出 语文和英语 或者英语和数学之和在一定范围内的人
举例: 100<(yuwen+yingyu)<120 的名单
如果写查询语句?
```
"user": {
"aliases": {},
"mappings": {
"userclass": {
"properties": {
"name": {
"type": "long"
},
"kaoshi": {
"properties": {
"yuwen": {
"type": "long"
},
"suxue": {
"type": "long"
},
"yingyu": {
"type": "long"
}
}
}
}
```
数据
{"name":"张三","kaoshi":{"yuwen":80,"yingyu":60,"suxue":99}}
{"name":"李四","kaoshi":{"yuwen":20,"yingyu":60,"suxue":45}}
{"name":"二熊","kaoshi":{"yuwen":60,"yingyu":50,"suxue":39}}
...
想查询出 语文和英语 或者英语和数学之和在一定范围内的人
举例: 100<(yuwen+yingyu)<120 的名单
如果写查询语句?
3 个回复
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自: daowojia
daowojia
赞同来自: lbx6z
最终都要用 script
方案一 :
"query": {
"bool": {
"must": [
[ {
"script": {
"script": {
"source": "(doc['kaoshi.yuwen'].value+doc['kaoshi.yingyu'].value)<10"
}
}
},{小于条件}
}}
方案二
https://www.elastic.co/guide/e ... .html
yayg2008
赞同来自: