2

我在我的 Ajax 调用中使用以下 POST 请求,但是我无法添加其他搜索条件。我还希望能够专门使用通配符搜索许多其他字段。示例“j*”的名字和“p*”的姓氏。我如何向这种类型的查询添加另外两个条件。当它是 GET 请求时,我知道如何在 curl 请求中执行此操作,但不确定如何将其作为 POST 请求执行。

在 GET 请求上,我只需添加以下内容。

+%2bfirstName:j*

POST 请求

{
    "query": {
        "filtered": {
            "query": {
                "range": {
                    "date": {
                        "include_lower": true,
                        "include_upper": false,
                        "from": "1999-01-01",
                        "to": "2002-01-01"
                    }
                }
            },
            "filter": {
                "term": {
                    "locationNumber": "453"
                }
            }
        }

    }
}
4

1 回答 1

3

您可以使用bool query在查询中组合多个条件。例如:

{
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "range": {
                                "date": {
                                    "include_lower": true,
                                    "include_upper": false,
                                    "from": "1999-01-01",
                                    "to": "2002-01-01"
                                }
                            }
                        },
                        {
                            "wildcard": {
                                "firstName": "j*"
                            }
                        }
                    ]
                }
            },
            "filter": {
                "term": {
                    "locationNumber": "453"
                }
            }
        }

    }
}
于 2013-01-16T14:42:02.193 回答