我在 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"
}
}
}
}
}
最佳答案
您可以使用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"
}
}
}
}
}
关于ajax - Elasticsearch 请求中的多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14359619/