Elasticsearch 查询指南:基础操作及示例
Elasticsearch 是一个开源搜索引擎,它提供了一个基于 RESTful API 的全文搜索和分析引擎。以下是一些基本的 Elasticsearch 查询操作:
- 查询所有文档:
GET /_search
{
'query': {
'match_all': {}
}
}
- 精确匹配查询:
GET /_search
{
'query': {
'match': {
'title': 'Elasticsearch'
}
}
}
- 多个匹配查询:
GET /_search
{
'query': {
'multi_match': {
'query': 'Elasticsearch',
'fields': ['title', 'content']
}
}
}
- 范围查询:
GET /_search
{
'query': {
'range': {
'age': {
'gte': 18,
'lte': 30
}
}
}
}
- 布尔查询:
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 查询,请查看官方文档。
原文地址: https://www.cveoy.top/t/topic/k6sT 著作权归作者所有。请勿转载和采集!