elasticsearch - 术语查询返回 0 个结果 elasticsearch
问题描述
我有以下文件:
{
"_index": "testrest",
"_type": "testrest",
"_id": "sadfasdfw1",
"_score": 1,
"_source": {,
"s_item_name": "Create",
"request_id": "35",
"Result": "Match",
}
},
我正在尝试获取具有字段term
值和.Match
Result
request_id
35
这是我的查询:
{
"query": {
"bool": {
"must": [
{ "term": { "Result": "Match" }}
],
"filter": {
"term": {
"request_id": "35"
}
}
}
}
}
但我得到了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"
}
}
}
}
}
或者
{
"query": {
"bool": {
"must": [
{ "term": { "Result.keyword": "Match" }} <-- use term query on keyword field
],
"filter": {
"term": {
"request_id": "35"
}
}
}
}
}
推荐阅读
- mysql - 是否有一种获取最后一行数据并将其递增/递减 1 的 SQL 方法?
- angular - 从 cmd 调用 Angular 语言服务
- python - 有没有办法在 Python 中识别 RNDIS 连接/适配器?然后配置那个适配器?
- c++ - 在结构中添加变量结构作为有效负载,以便在 C++ 中通过 udp 发送
- node.js - jest.mock 找不到模块
- java - 如何使用 selenium webdriver 单击角度元素?
- python - 在子查询中使用查询集时,Django 只返回 id 字段而不是整个对象
- javascript - 无法下载带有过滤器的画布图像
- reactjs - React-Table:在父组件中获取 selectedRowIds
- javascript - 在 VueJS 中动态更新的可编辑下拉列表