ElasticSearch38:初识搜索引擎_上机动手实战常用的各种query搜索语法
2018-01-04 11:21
691 查看
1.match all
GET /company/employee/_search
{
"query": {
"match_all": {}
}
}
2.match
GET /company/employee/_search
{
"query": {
"match": {
"name": "tom"
}
}
}
执行结果:
3.multi_match
例子:
表示title或者content中包含elasticsearch都行,都可以查询出来
GET /website/article/_search
{
"query": {
"multi_match": {
"query": "elasticsearch",
"fields": ["title","content"]
}
}
}
执行结果
4.range query
可以放到query,也可以放到filter里面
例子:查询年龄大于等于30的员工
GET /company/employee/_search
{
"query": {
"range": {
"age": {
"gte": 30
}
}
}
}
执行结果:
5.term query
将term中字段指定的值作为整个值,去倒排索引中查找
例子:因为倒排索引中没有elasticsearch is good这个词(倒排索引中有elasticsearch, is, good三个词),所以执行结果没有任何数据
GET /website/article/_search
{
"query": {
"term": {
"content": "elasticsearch is good"
}
}
}
执行结果
查看分词效果:
GET /_analyze
{
"text": "elasticsearch is good",
"analyzer": "standard"
}
分词结果:
match的执行:
GET /website/article/_search
{
"query": {
"match": {
"content": "elasticsearch is good"
}
}
}
执行结果
6.query exist(2.x中提供,后面的取消了)
GET /_search
{
"query": {
"exists":{
"title":"hello"
}
}
}
GET /company/employee/_search
{
"query": {
"match_all": {}
}
}
2.match
GET /company/employee/_search
{
"query": {
"match": {
"name": "tom"
}
}
}
执行结果:
{ "took": 6, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "company", "_type": "employee", "_id": "1", "_score": 0.2876821, "_source": { "address": { "province": "zhejiang", "city": "wenzhou", "country": "china" }, "name": "tom", "age": 31, "join_date": "2015-01-02" } } ] } }
3.multi_match
例子:
表示title或者content中包含elasticsearch都行,都可以查询出来
GET /website/article/_search
{
"query": {
"multi_match": {
"query": "elasticsearch",
"fields": ["title","content"]
}
}
}
执行结果
{ "took": 255, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 2, "max_score": 0.25316024, "hits": [ { "_index": "website", "_type": "article", "_id": "1", "_score": 0.25316024, "_source": { "title": "my elasticsearch article1", "content": "elasticsearch is good", "author_id": 10010 } }, { "_index": "website", "_type": "article", "_id": "3", "_score": 0.25316024, "_source": { "title": "my elasticsearch article1", "content": "elasticsearch is bad", "author_id": 100 } } ] } }
4.range query
可以放到query,也可以放到filter里面
例子:查询年龄大于等于30的员工
GET /company/employee/_search
{
"query": {
"range": {
"age": {
"gte": 30
}
}
}
}
执行结果:
{ "took": 4, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 1, "hits": [ { "_index": "company", "_type": "employee", "_id": "1", "_score": 1, "_source": { "address": { "province": "zhejiang", "city": "wenzhou", "country": "china" }, "name": "tom", "age": 31, "join_date": "2015-01-02" } } ] } }
5.term query
将term中字段指定的值作为整个值,去倒排索引中查找
例子:因为倒排索引中没有elasticsearch is good这个词(倒排索引中有elasticsearch, is, good三个词),所以执行结果没有任何数据
GET /website/article/_search
{
"query": {
"term": {
"content": "elasticsearch is good"
}
}
}
执行结果
{ "took": 3, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 0, "max_score": null, "hits": [] } }
查看分词效果:
GET /_analyze
{
"text": "elasticsearch is good",
"analyzer": "standard"
}
分词结果:
{ "tokens": [ { "token": "elasticsearch", "start_offset": 0, "end_offset": 13, "type": "<ALPHANUM>", "position": 0 }, { "token": "is", "start_offset": 14, "end_offset": 16, "type": "<ALPHANUM>", "position": 1 }, { "token": "good", "start_offset": 17, "end_offset": 21, "type": "<ALPHANUM>", "position": 2 } ] }
match的执行:
GET /website/article/_search
{
"query": {
"match": {
"content": "elasticsearch is good"
}
}
}
执行结果
{ "took": 27, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 3, "max_score": 0.7594807, "hits": [ { "_index": "website", "_type": "article", "_id": "1", "_score": 0.7594807, "_source": { "title": "my elasticsearch article1", "content": "elasticsearch is good", "author_id": 10010 } }, { "_index": "website", "_type": "article", "_id": "2", "_score": 0.5063205, "_source": { "title": "my hadoop article1", "content": "hadoop is good", "author_id": 10010 } }, { "_index": "website", "_type": "article", "_id": "3", "_score": 0.5063205, "_source": { "title": "my elasticsearch article1", "content": "elasticsearch is bad", "author_id": 100 } } ] } }
6.query exist(2.x中提供,后面的取消了)
GET /_search
{
"query": {
"exists":{
"title":"hello"
}
}
}
相关文章推荐
- ElasticSearch36:初识搜索引擎_快速上机动手实战Query DSL搜索语法
- ElasticSearch39:初识搜索引擎_上机动手实战多搜索条件组合查询
- ElasticSearch48:初识搜索引擎_上机动手实战基于scroll技术滚动搜索大量数据
- ElasticSearch40:初识搜索引擎_上机动手实战如何定位不合法的搜索以及其原因
- ElasticSearch41:初识搜索引擎_上机动手实战如何定制搜索结果的排序规则
- ElasticSearch25:初识搜索引擎_快速掌握query string search语法以及_all metadata原理揭秘
- es的几种常用query搜索语法
- ElasticSearch47:初识搜索引擎_搜索相关参数梳理以及bouncing results问题解决方法
- 第十三篇 elasticsearch的Query DSL搜索语法
- Elasticsearch中的索引管理和搜索常用命令总结
- ElasticSearch27:初识搜索引擎_精确匹配与全文检索的对比分析
- elasticsearch 常用语法
- ElasticSearch43:初识搜索引擎_相关度评分TF&IDF算法揭秘
- ElasticSearch45:初识搜索引擎_分布式搜索引擎内核揭秘之query phase
- 一些常用的GOOGLE、YAHOO、BAIDU三大搜索引擎搜索命令
- 第三百七十一节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)用Django实现我的搜索以及热门搜索
- HubbleDotNet搜索引擎+盘古分词在站内搜索中的应用实战
- ElasticSearch实战:个人博客搜索和首页内容展示
- 搜索引擎 ElasticSearch 之 步步为营1 【环境搭建&初识ElasticSearch】
- 学习用Node.js和Elasticsearch构建搜索引擎(6):实际项目中常用命令使用记录