我有一份专家文件如下:
{
"_id" : "test@domain.com",
"age" : 12,
"hobbiles" : ["Singing", "Dancing"]
},
{
"_id" : "test1@domain.com",
"age" : 7,
"hobbiles" : ["Coding", "Chess"]
}我将电子邮件存储为id、age和hobbiles,兴趣爱好是嵌套型的,年龄是长的,我想查询id、age和hobbiles,如下所示:
Select * FROM tbl where _id IN ('val1', 'val2') AND age > 5 AND hobbiles should match with Chess or Dancing在弹性搜索中我能做些什么?我使用的是OpenSearch 1.3 (最新):
发布于 2022-08-31 17:05:18
我会怀疑字段hobbiles是关键字,然后查询建议:
PUT test
{
"mappings": {
"properties": {
"age": {
"type": "long"
},
"hobbiles": {
"type": "keyword"
}
}
}
}
POST test/_doc/test@domain.com
{
"age": 12,
"hobbiles": [
"Singing",
"Dancing"
]
}
POST test/_doc/test1@domain.com
{
"age": 7,
"hobbiles": [
"Coding",
"Chess"
]
}
GET test/_search
{
"query": {
"bool": {
"filter": [
{
"terms": {
"_id": [
"test1@domain.com",
"test@domain.com"
]
}
}
],
"must": [
{
"range": {
"age": {
"gt": 5
}
}
},
{
"terms": {
"hobbiles": [
"Coding",
"Chess"
]
}
}
]
}
}
}https://stackoverflow.com/questions/73559083
复制相似问题