给出elasticsearch所有语法例子
时间: 2023-08-31 19:05:21 浏览: 79
1. 简单查询语句:
```
GET /index-name/_search?q=title:elasticsearch
```
2. 使用查询字符串查询语句:
```
GET /index-name/_search?q=title:(elasticsearch OR search)
```
3. 基本匹配查询语句:
```
GET /index-name/_search
{
"query": {
"match": {
"title": "elasticsearch"
}
}
}
```
4. 多词查询语句:
```
GET /index-name/_search
{
"query": {
"match_phrase": {
"title": "elasticsearch search"
}
}
}
```
5. 布尔查询语句:
```
GET /index-name/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "elasticsearch" } },
{ "match": { "description": "search" } }
]
}
}
}
```
6. 范围查询语句:
```
GET /index-name/_search
{
"query": {
"range": {
"age": {
"gte": 18,
"lte": 30
}
}
}
}
```
7. 模糊查询语句:
```
GET /index-name/_search
{
"query": {
"fuzzy": {
"title": {
"value": "elasterc",
"fuzziness": "AUTO"
}
}
}
}
```
8. 正则表达式查询语句:
```
GET /index-name/_search
{
"query": {
"regexp": {
"title": "elasticsearch.*"
}
}
}
```
9. 短语前缀查询语句:
```
GET /index-name/_search
{
"query": {
"match_phrase_prefix": {
"title": {
"query": "elasticsearch s",
"max_expansions": 10
}
}
}
}
```
10. 嵌套查询语句:
```
GET /index-name/_search
{
"query": {
"nested": {
"path": "comments",
"query": {
"match": {
"comments.comment": "elasticsearch"
}
}
}
}
}
```
阅读全文