假设我有一种查询语言,可以将“自然”语言查询解析为弹性搜索查询。
假设我们有以下查询:
(type == "my-type" || device_id == "some-device-id") && id == "123456789"
如何在弹性搜索中实现这一点?
我试过:
{
"bool": {
"filter": {
"term": {
"id": "123456789"
}
},
"should": [
{
"term": {
"type": "my-type"
}
},
{
"term": {
"device_id": "some-device-id"
}
}
]
}
}
但这不是我想要的。
我究竟做错了什么?
映射:
{
"mappings": {
"_doc": {
"properties": {
"accepted_at": {
"type": "date",
"format": "strict_date_optional_time||date_time||epoch_millis"
},
"created_at": {
"type": "date",
"format": "strict_date_optional_time||date_time||epoch_millis"
},
"device_id": {"type": "keyword"},
"id": {"type": "keyword"},
"location": {"type": "geo_point"},
"message_id": {"type": "keyword"},
"type": {"type": "keyword"}
}
}
}
}