我有以下文件:
{
"_index": "testrest",
"_type": "testrest",
"_id": "sadfasdfw1",
"_score": 1,
"_source": {,
"s_item_name": "Create",
"request_id": "35",
"Result": "Match",
}
},
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取在field 和of中term具有值的记录。MatchResultrequest_id35
这是我的查询:
{
"query": {
"bool": {
"must": [
{ "term": { "Result": "Match" }}
],
"filter": {
"term": {
"request_id": "35"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我正在得到0结果。
不过,替换term为match给了我结果。
这是因为Result是一个text字段,因此对其进行分析并将值索引为match而不是Match。
一般来说,您不应该使用term查询,而match更喜欢使用查询。对于你的情况,这可以解决问题。
如果您绝对想使用term查询并有一个名为 的字段Result.keyword,那么您也可以这样做。
回顾一下:
{
"query": {
"bool": {
"must": [
{ "match": { "Result": "Match" }} <-- use match query
],
"filter": {
"term": {
"request_id": "35"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者
{
"query": {
"bool": {
"must": [
{ "term": { "Result.keyword": "Match" }} <-- use term query on keyword field
],
"filter": {
"term": {
"request_id": "35"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1047 次 |
| 最近记录: |