elasticsearch查询

(1)简单查询

curl -XGET http://127.0.0.1:9201/_search
curl -XGET http://127.0.0.1:9201/test231208/_search
curl -XGET http://127.0.0.1:9201/test231208/_doc/_search
curl -XGET http://127.0.0.1:9201/test231208/_doc/id

(2)match、match_all、multi_match查询,模糊查询,即先分词后查询;match_all查询全部数据;match针对一个field做查询,multi_match针对多个field做查询,任意一个字段符合条件就行

curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"match": {
			"name": "jerry"
		}
	}
}'
curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"match_all": {}
	}
}'
curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"multi_match": {
			"query": "jerry",
			"fields": [
				"name"
			]
		}
	}
}'

(3)term查询或range查询,精确查询

curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"term": {
			"age": 2
		}
	}
}'
curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"range": {
			"age": {
				"gte": 3,
				"lte": 4
			}
		}
	}
}'

(4)bool查询,一个或多个查询子句的组合,must表示必须匹配(类似与)、should表示选择性匹配(类似或)、must_not表示必须不匹配(类似非)、filter表示过滤条件

curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"bool": {
			"must": [
				{
					"match": {
						"name": "tom"
					}
				},
				{
					"match": {
						"age": 2
					}
				}
			],
			"should": [
				{
					"match": {
						"name": "tom"
					}
				},
				{
					"match": {
						"name": "jerry"
					}
				}
			],
			"must_not": [
				{
					"match": {
						"name": "diana"
					}
				}
			],
			"filter": [
				{
					"range": {
						"age": {
							"gte": 2,
							"lte": 4
						}
					}
				}
			]
		}
	}
}'

(5)查询部分属性字段、分页和排序

curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"match_all": {}
	},
	"_source": {
		"includes": [
			"age",
			"name"
		]
	},
	"from": 0,
	"size": 10,
	"sort": [
		{
			"age": {
				"order": "asc"
			}
		}
	]
}'

(6)group by分组

curl -XGET http://127.0.0.1:9201/test231208/_search -d 
'{
	"query": {
		"range": {
			"gmt_create": {
				"gte": "20230101000000",
				"lte": "20240101000000"
			}
		}
	},
	"from": 0,
	"size": 0,
	"sort": [],
	"aggs": {
		"group_by_key": {
			"terms": {
				"field": "age"
			}
		}
	}
}'

响应体,如下

{
    "took": 7,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "group_by_key": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": 2,
                    "doc_count": 1
                },
                {
                    "key": 4,
                    "doc_count": 1
                }
            ]
        }
    }
}

相关推荐

  1. elasticsearch查询

    2024-01-17 13:44:02       57 阅读
  2. Go查询Elasticsearch

    2024-01-17 13:44:02       61 阅读
  3. Elasticsearch一些函数查询

    2024-01-17 13:44:02       48 阅读
  4. Elasticsearch 查询语法

    2024-01-17 13:44:02       61 阅读
  5. ElasticSearch DSL Bool查询

    2024-01-17 13:44:02       64 阅读
  6. Elasticsearch 查询语句概述

    2024-01-17 13:44:02       59 阅读
  7. ElasticSearch聚合查询

    2024-01-17 13:44:02       35 阅读
  8. ElasticSearch的DSL查询

    2024-01-17 13:44:02       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-17 13:44:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-17 13:44:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-17 13:44:02       82 阅读
  4. Python语言-面向对象

    2024-01-17 13:44:02       91 阅读

热门阅读

  1. Kotlin Async

    2024-01-17 13:44:02       52 阅读
  2. Python 发微信:实现自动化沟通的利器

    2024-01-17 13:44:02       53 阅读
  3. sqlserver2012 跨服务器查询

    2024-01-17 13:44:02       66 阅读
  4. ARCGIS PRO SDK 地图图层单一符号化_____面图层

    2024-01-17 13:44:02       57 阅读
  5. Flutter开发 键盘弹起导致底部溢出问题

    2024-01-17 13:44:02       57 阅读
  6. C#学习教程

    2024-01-17 13:44:02       57 阅读
  7. 黑洞数(C语言)

    2024-01-17 13:44:02       52 阅读
  8. 快速了解STM32的ADC功能,从入门到精通

    2024-01-17 13:44:02       55 阅读
  9. Github Copilot 的使用方法和快捷键*

    2024-01-17 13:44:02       76 阅读
  10. Nue.js 是什么?

    2024-01-17 13:44:02       47 阅读
  11. What is `HttpServletRequestWrapper` does?

    2024-01-17 13:44:02       64 阅读
  12. ConcurrentHashMap源码解析

    2024-01-17 13:44:02       66 阅读