elasticsearch - 使用大全

1.term

term 根据 keyword字段 精确匹配

实例

GET index3/_search
{
  "query": {
    "term": {
      "book_name": "设计"
    }
  }
}

2. terms

terms 根据 keyword字段 精确匹配

实例

GET index3/_search
{
  "query": {
    "terms": {
      "book_name": ["设计", "李四"]
    }
  }
}

3. match

进行模糊查询

实例

GET index3/_search
{
  "query": {
    "match": {
      "book_name": "设计"
    }
  }
}

4. multi_match

多个字段进行模糊查询

实例

GET index3/_search
{
  "query": {
    "multi_match": {
      "query": "java"
      "fileds": ["book_name", "author"]
    }
  }
}

5. values

根据多个id查询多个document

实例

GET index3/_search
{
  "query": {
    "ids": {
      "values": ["1", "2", '3']
    }
  }
}

6. prefix

根据指定字段前缀进行查询

实例

GET index3/_search
{
  "query": {
    "prefix": {
      "author": {
         "value": "张"
      }
    }
  }
}

7. fuzzy

模糊查询,输入大概的内容,es检索相关的数据

实例

GET index3/_search
{
  "query": {
    "fuzzy": {
      "book_name": {
         "value": "jav" #查询java
      }
    }
  }
}

8. wildcard

正则查询

实例

GET index3/_search
{
  "query": {
    "wildcard": {
      "author": {
         "value": "张*" 
      }
    }
  }
}

9. range

根据范围查询

实例

GET index3/_search
{
  "query": {
    "range": {
      "book_id": {
         "gte": "101",
         "lte": "105" 
      }
    }
  }
}

10. 分页查询

分页查询

实例

GET index3/_search
{
  "query": {
     “match_all”: {}   # 匹配所有数据
    },
   _source: ["book_id", "book_name"], # 指定查询的数据
   "from": 0,
   "size": 20
  }
}

11. bool -> must(and)、should(or)、 must_not(not)

复合查询

实例

GET index3/_search
{
  "query": {
     “bool”: {
		"must": [
			{
				"match": {
					"book_name": "java"
				}
			},
			{
				"match": {
					"author": "张三"
				}
			},
		]
	}  
  }
}

11. filter

与must用法一样,不计算分数,会对经常被过滤的数据添加缓存

实例

GET index3/_search
{
  "query": {
     “bool”: {
		"filter": [
			{
				"match": {
					"book_name": "java"
				}
			},
			{
				"match": {
					"author": "张三"
				}
			},
		]
	}  
  }
}

11. highlight

高亮查询

实例

GET index3/_search
{
  "query": {
     "multi_match": {
		"query": "java",
		"fileds": ["book_name", book_author]	
	}
  },
  _source: ["book_id", "book_name", "book_author"],
  "highlight": {
		"fields": {
			"book_name": {}
		},
		"pre_tags": "<label style='color:red'>",
		"post_tags": "<tags>"
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值