[英]Elasticsearch string matching multiple fields in query
我正在嘗試查詢我的彈性搜索數據庫並匹配幾個字段,但是,我得到:
[匹配] 格式錯誤的查詢,應為 [END_OBJECT],但找到了 [FIELD_NAME]
這很奇怪,因為我肯定能夠使用match
然后我的字段名稱來匹配某些文本嗎?
我要查詢的字段在我的data
object 中,這是自定義的,由於在這里添加(點)不起作用,所以我將其包裝起來,我的數據:
{
"_index": "my_table",
"_type": "_doc",
"_id": "IVnGuXcBt3ZsPNCw23Eg",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"mappings": {
"properties": {
"period_from": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss",
"fielddata": true
},
"period_to": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss",
"fielddata": true
},
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss",
"fielddata": true
},
"updated_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss",
"fielddata": true
}
}
},
"data": {
"dataset": "events",
"event_category": "test1",
"event_action": "test2",
"event_count": "199",
"period_from": "2021-02-19 00:02:00",
"period_to": "2021-02-19 10:02:29",
"created_at": "2021-02-19 10:02:79",
"updated_at": "2021-02-19 10:02:79"
},
"period_from": "2021-02-19 00:02:00",
"period_to": "2021-02-19 10:02:29",
"created_at": "2021-02-19 10:02:18",
"updated_at": "2021-02-19 10:02:18"
}
}
我在這里錯過了什么:
events = await elastic.find('my_table', {
query: {
match: {
'data.event_category': 'test1'
},
match: {
'data.event_action': 'test2'
},
range: {
period_from: {
gte: moment(from).format('YYYY-MM-DD HH:MM:SS')
},
period_to: {
lte: moment(to).format('YYYY-MM-DD HH:MM:SS')
}
}
}
})
正確設置日期字段的映射后,請使用以下命令:
{
query: {
bool: {
must: [
{
match: {
"data.event_action": "test2"
}
},
{
range: {
period_from: {
gte: moment(from).format('YYYY-MM-DD HH:MM:SS')
}
}
},
{
range: {
period_to: {
lte: moment(to).format('YYYY-MM-DD HH:MM:SS')
}
}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.