elasticsearch - Elasticsearch“搜索查询词”为 _doc 类型索引中的嵌套对象键返回 0 个提示
问题描述
我在 elasticsearch 中搜索时遇到问题。每当我尝试按以下 curl 之类的术语进行搜索时,都会得到我想要的结果。
curl --location --request GET 'http://xx.xx.xx.xx:xxxx/XXXXXX/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
"query": {
"term": {
"time": {
"value": "2021-02-09T00:09:49.457Z",
"boost": 1.0
}
}
}
}
'
响应示例。该类型表示 _doc,因此嵌套查询应该以相同的方式工作。
{"hits": [
{
"_index": "XXXX",
"_type": "_doc",
"_id": "xxxxx",
"_score": 1.0,
"_source": { ... }
]}
但是,当我尝试搜索嵌套键时,响应中的命中率为 0。
curl --location --request GET 'http://xx.xx.xx.xx:xxxx/XXXXXX/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
"query": {
"term": {
"code.type": {
"value": "animals",
"boost": 1.0
}
}
}
}
知道可能出了什么问题吗?
解决方案
如果您确定您尝试搜索的文档存在,请确保您的字段的索引映射以及“code”字段是否是使用“code.keyword”进行关键字搜索,如果没有,请删除“boost”字段不能再次更改查询语法和策略,例如叶子查询
curl -XGET "http://xx.xx.xx.xx:xxxx/XXXXXX/_search" -H 'Content-Type: application/json' -d'{ "query": {"match": { "code.type": "animals" }}}'
如果您的字段是关键字
curl -XGET "http://xx.xx.xx.xx:xxxx/XXXXXX/_search" -H 'Content-Type: application/json' -d'{ "query": {"match": { "code.type": "animals" }}}'
随时更新对话和评论。
推荐阅读
- authentication - 当需要对客户端进行身份验证时,使用长期令牌还是加密存储用户名和密码?
- javascript - 只读属性在打字稿中部分工作?
- php - 我无法访问 PHP 中的页面
- python - VSCode 中的 Intellisense 和 Python 类型提示
- linux - 如何使用 bash 命令行重命名以序列开头的文件
- mongodb - 如何在 Mongoose 的聚合查询中访问字段值
- python - 跳出 For 循环和 If 语句
- r - 一个一个地绘制二进制向量的条件组合
- kotlin - kotlin:如何制作可滑动的堆栈卡视图?
- ffmpeg - 在 vlc 上接收像素化和滞后的 rtsp 流时