好的想法是十分钱一打,真正无价的是能够实现这些想法的人。

请教elasticsearch里面如何查询 字段A=xxx and (字段B<>xxx or 字段C=xxx ) 这种语法

Elasticsearch | 作者 wuzx | 发布于2017年11月21日 | 阅读数:1875

请教elasticsearch里面如何写 字段A=xxx and (字段B<>xxx  or 字段C=xxx ) 这样的查询条件,多谢了
已邀请:

白衬衣 - 金桥

赞同来自:

"query":{"filtered":{"query":{"query_string":{"query":"A:"xxx" AND (NOT B:"xxx" or C:"XXX")"}}

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

wuzx

赞同来自:

最后使用should方式{
    "min_score": 1,
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "createTime": "now/M"
                    }
                },
                {
                    "terms": {
                        "orderTypeId": [
                            "b1",
                            "b2"
                        ]
                    }
                },
                {
                    "bool": {
                        "should": [
                            {
                                "bool": {
                                    "must_not": [
                                        {
                                            "term": {
                                                "acceptChannel": "XXX"
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "bool": {
                                    "must": [
                                        {
                                            "range": {
                                                "hastenTimes": {
                                                    "gt": 0
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ],
            "must_not": [
                {
                    "term": {
                        "orderStatus": "XXX"
                    }
                },
                {
                    "term": {
                        "flowId": "1"
                    }
                }
            ]
        }
    },
    "from": 0,
    "size": 5
}

要回复问题请先登录注册