【问题标题】:Elastic Query for SQL like query用于类似 SQL 的查询的弹性查询
【发布时间】:2021-09-16 04:40:03
【问题描述】:

想要在弹性搜索中进行搜索,就像我们在 SQL 查询 = (age = 25 and name = xyz) 中所做的那样。

这适用于单个字段和单个数据。

【问题讨论】:

  • 你的问题是什么?
  • 我想在弹性搜索文档中搜索 SQL 查询 => 年龄 = 25 和名称 = xyz

标签: elasticsearch elasticsearch-query


【解决方案1】:

是的,很有可能,只需使用下面的 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
                    }
                }
            ]
        }
    }
}

【讨论】:

    【解决方案2】:

    除了接受的答案

    POST _sql?format=txt {
    "query":"SELECT age, name FROM collection WHERE age=25 AND name ='xyz'"
    }
    

    另请参阅 https://www.elastic.co/what-is/elasticsearch-sql

    【讨论】:

      猜你喜欢
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      相关资源
      最近更新 更多