将此发布到弹性搜索会引发异常 org.elasticsearch.index.query.QueryParsingException:[myapp]没有为[match]注册过滤器
http://localhost:9200/
GET myapp/_search/
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"match": {
"userName": "Micky"
}
},
{
"match": {
"Age": 21
}
}
],
"should": [],
"must_not": []
}
}
}
},
"from": 0,
"size": 20
}
为什么这个查询错了(技术细节)?
答案 0 :(得分:0)
没有名为match
的过滤器,您可以使用term
代替
POST myapp/_search/
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"userName": "Micky"
}
},
{
"term": {
"Age": 21
}
}
],
"should": [],
"must_not": []
}
}
}
},
"from": 0,
"size": 20
}
或使用constant_score
查询代替filtered
,因为您没有过滤器。
POST myapp/_search/
{
"query": {
"constant_score": {
"query": {
"bool": {
"must": [
{
"match": {
"userName": "Micky"
}
},
{
"match": {
"Age": 21
}
}
],
"should": [],
"must_not": []
}
}
}
},
"from": 0,
"size": 20
}