elasticsearch - ElasticSearch:Multi_fields 参数不起作用
问题描述
我有一个多字段参数“startTime”,下面是映射
"startTime" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
},
"raw" : {
"type" : "date",
"format" : "dd-MM-yyyy HH:mm:ss||dd-MM-yyyy||hour_minute_second"
}
}
}
我插入了一些文件
{
"orgId" => "backendorg",
"startTime" => "01-01-1980 06:32:51"
}
{
"orgId" => "backendorg",
"startTime" => "01-01-1980 06:35:51"
}
{
"orgId" => "backendorg",
"startTime" => "01-01-1980 06:39:51"
}
当我尝试根据以下查询过滤 startTime 时,它返回空结果
{
"query": {
"bool": {
"must": [
{
"term": {
"orgId": {
"value": "backendorg",
"boost": 1
}
}
},
{
"bool": {
"should": [
{
"range": {
"startTime": {
"from": "01-01-1980 06:32:51",
"to": "01-01-1980 06:39:51",
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
]
}
}
]
}
}
}
有人能告诉我我的查询或映射有什么问题吗?
解决方案
由于您的日期字段是一个子字段startTime.raw
,因此您需要在range
查询中使用它
{
"range": {
"startTime.raw": { <----- change this
"from": "01-01-1980 06:32:51",
"to": "01-01-1980 06:39:51",
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
]
推荐阅读
- postgresql - Postgres:psql:致命:Windows 10 中不存在数据库“root”
- laravel - Laravel Mix - 如何观察多个入口点的变化
- swift - 在嵌套容器中查找后代按钮
- python - DatetimeIndex 不能执行操作的意思
- android - Android导航组件动画从活动返回到片段
- java - 在 JTable 上使用 RowSorter.SortKey 时下移空行
- android - 如何在 LinearLoyout ImageView 中设置点击监听器
- microservices - 使用 Spring Boot 的微服务中的 Active Standby
- java - 正则表达式模式:未闭合组
- c++ - 如何检查一个单词是否存在于向量中