查询在下面
{"from" : 0, "size" : 100,"query": {"match_all": {}}})
如果filter
是name
,我需要从match_all test
我尝试过{"from" : 0, "size" : 100,"query": {"match_all": {}}, "filter": [ "term": { "name": "test" }}]}
我收到错误消息“ [过滤器]中START_ARRAY的未知密钥。”
答案 0 :(得分:2)
您需要将查询包装在bool查询中,尝试以下搜索查询:
{
"from":0,
"size":10,
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": [
{
"term": {
"grocery_name": "elastic"
}
}
]
}
}
}
更新1:
根据@Nons提到的评论
搜索查询:
条款查询返回的文档中,提供的文档中包含确切的条款 字段。
{
"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"
}
]
}
}
]
您甚至可以使用匹配查询来分析提供的文本 匹配之前。
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": {
"match": {
"parentName": "developer"
}
}
}
}
}
答案 1 :(得分:1)