Elasticsearch中多个布尔查询的限制大小

时间:2019-08-07 07:38:14

标签: elasticsearch

我必须从弹性搜索中搜索信息,因此对于该需求,我使用了多个布尔查询,但我想将每个布尔查询的大小限制为彼此不同的值,这意味着每个布尔查询都有自己的限制。所以为此,我将此代码用于全局查询。请您帮我一下,谢谢。

{
    "query": {
        "bool": {
            "filter": [
                {
                    "range": {
                        "@timestamp": {
                            "from": "date1",
                            "to": "date2"
                        }
                    }
                },
                {
                    "bool": {
                        "should": [
                            {
                                "bool": {
                                    "must": [
                                        { "match": { "name": "bn1" } },
                                        { "match": { "lastname": "l1" } },
                                        { "match": { "old": "30" } }
                                    ]
                                }
                            },
                            {
                                "bool": {
                                    "must": [
                                        { "match": { "name": "n2" } },
                                        { "match": { "lastname": "l2" } },
                                        { "match": { "old": "20" } }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以尝试MultiSearch多重搜索API允许在同一API中执行多个搜索请求。终结点是_msearch。

示例。如何实现3个查询的并集。

curl -XGET 'http://127.0.0.1:9200/my_index/_msearch?pretty=1'  -d '
{}
{"query" : {"text" : {"title" : "some words"}}, "size" : 5}
{}
{"query" : {"text" : {"title" : "some other words"}}, "size" : 5}
{}
{"query" : {"text" : {"title" : "other words"}}, "size" : 5}
'

enter image description here