美文网首页
超级复杂的 es bool 查询

超级复杂的 es bool 查询

作者: 潘旭 | 来源:发表于2020-08-06 15:14 被阅读0次
        def _build_post_data(self, keywords: List[str] = None):
    
            query = {
                "sort": [
                    {
                        "publish_time_str": {
                            "order": "desc"
                        }
                    },
                    {
                        "read_count": {
                            "order": "desc"
                        }
                    }
                ],
                "size": 10
            }
    
            if keywords:
                query["query"] = {
                    "bool": {
                        "must": [
                            {
                                "range": {
                                    "publish_time_str": {"from": "2020-08-01 00:00:00",
                                                         "to": "2020-08-06 23:00:00"}
                                }
                            },
    
                            {
                                "bool": {
                                    "should": [
    
                                    ]
                                }
                            }
                        ]
                    }
                }
    
                should = query["query"]["bool"]["must"][1]["bool"]["should"]
    
                for keyword in keywords:
                    match = {"match_phrase": {
                        "title": keyword
                    }}
                    should.append(match)
    
            return json.dumps(query)
    

    相关文章

      网友评论

          本文标题:超级复杂的 es bool 查询

          本文链接:https://www.haomeiwen.com/subject/gbozrktx.html