Elasticsearch 是一个开源搜索引擎,它提供了一个基于 RESTful API 的全文搜索和分析引擎。以下是一些基本的 Elasticsearch 查询操作:

  1. 查询所有文档:
GET /_search
{
    'query': {
        'match_all': {}
    }
}
  1. 精确匹配查询:
GET /_search
{
    'query': {
        'match': {
            'title': 'Elasticsearch'
        }
    }
}
  1. 多个匹配查询:
GET /_search
{
    'query': {
        'multi_match': {
            'query': 'Elasticsearch',
            'fields': ['title', 'content']
        }
    }
}
  1. 范围查询:
GET /_search
{
    'query': {
        'range': {
            'age': {
                'gte': 18,
                'lte': 30
            }
        }
    }
}
  1. 布尔查询:
GET /_search
{
    'query': {
        'bool': {
            'must': [
                { 'match': { 'title': 'Elasticsearch' } },
                { 'match': { 'content': 'search' } }
            ],
            'must_not': [
                { 'match': { 'status': 'draft' } }
            ],
            'should': [
                { 'match': { 'author': 'John' } },
                { 'match': { 'author': 'Jane' } }
            ]
        }
    }
}

这些只是 Elasticsearch 查询的一些基本操作,还有很多其他的查询类型和参数可以使用。要深入了解 Elasticsearch 查询,请查看官方文档。

Elasticsearch 查询指南:基础操作及示例

原文地址: https://www.cveoy.top/t/topic/k6sT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录