我正在尝试使用 AND 运算符从具有多个字段的 elasticsearch 中获取文档
对于下面的查询,我期望得到以下结果
AB-7000-8002-W
但我收到此错误消息 Unrecognized token 'get': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@40d2a7e8 ;行:1,列:5]
get my_index12/_search {
"query" : {
"bool": {
"should": [
{
"match": {
"code": {
"query": "AB-5000-6002-AK",
"operator": "and"
}
}
},
{
"match": {
"locale": {
"query": "en_US",
"operator": "and"
}
}
}
]
}
}
}
请在下面找到我的索引文件
{
"_index": "my_index12",
"_type": "doc",
"_id": "2",
"_score": 1,
"_source": {
"code": "AB-7000-8002-W",
"locale": "en_US"
}
},
{
"_index": "my_index12",
"_type": "doc",
"_id": "4",
"_score": 1,
"_source": {
"code": "AB-7000-8002-W",
"locale": "en_EU"
}
},
{
"_index": "my_index12",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"code": "sG66tsdF",
"locale": "en_US"
}
},
{
"_index": "my_index12",
"_type": "doc",
"_id": "3",
"_score": 1,
"_source": {
"code": "AB-7000-6002-WK",
"locale": "en_EU"
}
最佳答案
只需将 get my_index12/_search {
行中的花括号移动到下一行。
它应该有效。
为了获得同时满足这两个条件的结果,您必须使用must
子句而不是should
。 match
查询中的“AND”运算符不适用于您想要实现的用例。使用以下查询。
{
"query": {
"bool": {
"must": [
{
"match": {
"code": {
"query": "TE-7000-8002-W",
"operator": "and"
}
}
},
{
"match": {
"locale": {
"query": "en_US",
"operator": "and"
}
}
}
]
}
}
}
关于java - Elasticsearch 将多个字段与 AND 运算符匹配不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50833462/