查询如下{"from" : 0, "size" : 100,"query": {"match_all": {}}})
我需要 filter
来自 match_all if name
是 test
我试过 {"from" : 0, "size" : 100,"query": {"match_all": {}}, "filter": [ "term": { "name": "test" }}]}
我收到错误“[过滤器]中 START_ARRAY 的未知键。”)
最佳答案
您需要将您的查询包装在一个 bool 查询中,试试这个搜索查询:
{
"from":0,
"size":10,
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": [
{
"term": {
"grocery_name": "elastic"
}
}
]
}
}
}
更新 1:根据@Nons提到的评论
查询查询:
Terms query return documents that contain an exact term in a provided field.
{
"from":0,
"size":10,
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": [
{
"term": {
"parentName.keyword": "Developer" <-- note this
}
}
]
}
}
}
搜索结果:"hits": [
{
"_index": "stof_64275684",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"id": "1",
"name": "A",
"parentName": "Developer",
"Data": [
{
"id": "455",
"name": "Google",
"lastUpdatedDate": "2020-09-10",
"parent_id": "1"
}
],
"Function": [
{
"id": "1",
"name": "Major"
}
]
}
}
]
You can even use a match query where the provided text is analyzed before matching.
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": {
"match": {
"parentName": "developer"
}
}
}
}
}
关于elasticsearch - 如何在 Elasticsearch 中的 match_all 中使用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64275684/