【发布时间】:2021-09-16 04:40:03
【问题描述】:
想要在弹性搜索中进行搜索,就像我们在 SQL 查询 = (age = 25 and name = xyz) 中所做的那样。
这适用于单个字段和单个数据。
【问题讨论】:
-
你的问题是什么?
-
我想在弹性搜索文档中搜索 SQL 查询 => 年龄 = 25 和名称 = xyz
标签: elasticsearch elasticsearch-query
想要在弹性搜索中进行搜索,就像我们在 SQL 查询 = (age = 25 and name = xyz) 中所做的那样。
这适用于单个字段和单个数据。
【问题讨论】:
标签: elasticsearch elasticsearch-query
是的,很有可能,只需使用下面的 ES Mapping 和查询:
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"age" :{
"type" : "integer"
}
}
},
"settings": {
"index": {
"number_of_shards": "1",
"number_of_replicas": "1"
}
}
}
{
"name": "xyz",
"age" : 25
}
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "xyz"
}
},
{
"match": {
"age": 25
}
}
]
}
}
}
【讨论】:
除了接受的答案
POST _sql?format=txt {
"query":"SELECT age, name FROM collection WHERE age=25 AND name ='xyz'"
}
【讨论】: