想返回同时满足一下条件的数据:
conditions.id = 'stock' && conditions.num = 0
conditions.id = 'news' && conditions.num = 2
这是mapping
conditions.id = 'stock' && conditions.num = 0
conditions.id = 'news' && conditions.num = 2
这是mapping
{
"service": {
"type": "keyword"
},
"priority": {
"type": "integer"
},
"order": {
"properties": {
"order": {
"type": "integer"
},
"card": {
"type": "keyword"
}
}
},
"id": {
"type": "keyword"
},
"description": {
"type": "text",
"index": false
},
"conditions": {
"properties": {
"num": {
"type": "integer_range"
},
"id": {
"type": "keyword"
}
}
}
}
这是示例数据{
"id": 1,
"desc": "aabb",
"priority": 0,
"conditions": [
{
"id": "stock",
"num": {
"gte": 1
}
},
{
"id": "label",
"num": {
"gte": 0,
"lte":0
}
}
],
"service": [
"news",
"stock"
],
"order": [
{
"card": "stock_card1",
"order": 2
},
{
"card": "news",
"order": 1
}
]
}
{
"id": 1,
"desc": "aabb",
"priority": 0,
"conditions": [
{
"id": "stock",
"num": {
"gte": 0,
"lte": 0
}
},
{
"id": "label",
"num": {
"gte": 1
}
}
],
"service": [
"stock",
"news"
],
"order": [
{
"card": "stock_card1",
"order": 1
},
{
"card": "news",
"order": 2
}
]
}
然后我写的DSL返回不了想要的结果,这样写的结果就是直接俩文档都返回了{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"conditions.num": 0
}
},
{
"term": {
"conditions.id": "stock"
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"conditions.num": 2
}
},
{
"term": {
"conditions.id": "label"
}
}
]
}
}
]
}
}
}
2 个回复
God_lockin
赞同来自:
结果目前是可以满足的,但是用query_string不是很方便写在代码里动态生成,有没有大佬有更好的方式可以的解决的?
mapping:
然后用俩嵌套的query string来限定条件
结果目前是可以满足的
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自: