DSL搜索(二)

1.查询所有

1.1查询所有数据 match_all

 1.2查询某些字段

1.3可视化查询

在head插件的页面上也可以查询

点击基本查询,选择一个索引,选择must,match_all,点击搜索,就能查询所有数据

2.分页 from、size

共12条数据,第一页

 第一页返回了10条数据

{
	"took": 3,
	"timed_out": false,
	"_shards": {
		"total": 3,
		"successful": 3,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 12,
			"relation": "eq"
		},
		"max_score": 1,
		"hits": [
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1002",
				"_score": 1,
				"_source": {
					"birthday": "1993-01-24",
					"nickname": "周杰棍",
					"age": 19
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1003",
				"_score": 1,
				"_source": {
					"birthday": "1996-01-14",
					"nickname": "飞翔的巨鹰",
					"age": 20
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1008",
				"_score": 1,
				"_source": {
					"birthday": "1995-06-14",
					"nickname": "慕学习",
					"age": 19
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1011",
				"_score": 1,
				"_source": {
					"birthday": "1989-08-14",
					"nickname": "皮特帕克",
					"age": 31
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1007",
				"_score": 1,
				"_source": {
					"birthday": "1985-05-14",
					"nickname": "gamexbox",
					"age": 19
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1001",
				"_score": 1,
				"_source": {
					"birthday": "1922-12-24",
					"nickname": "慕课网",
					"age": 18
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1004",
				"_score": 1,
				"_source": {
					"birthday": "1988-02-14",
					"nickname": "水中鱼",
					"age": 22
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1005",
				"_score": 1,
				"_source": {
					"birthday": "1989-03-14",
					"nickname": "ps游戏机",
					"age": 25
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1006",
				"_score": 1,
				"_source": {
					"birthday": "1993-04-14",
					"nickname": "我叫小慕",
					"age": 19
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1009",
				"_score": 1,
				"_source": {
					"birthday": "1998-07-14",
					"nickname": "骚年轮",
					"age": 22
				}
			}
		]
	}
}

第二页返回2条数据

 3. term与match

3.1 精确匹配,不分词 term

3.1.1 dsl查询

返回三条数据,如下,与3.2.1做对比

terms:数组查询,可查询多个值

返回了4条数据,desc中包含“慕课网”的数据,以及desc中包含“骚年”的数据 

{
	"took": 203,
	"timed_out": false,
	"_shards": {
		"total": 3,
		"successful": 3,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 4,
			"relation": "eq"
		},
		"max_score": 1,
		"hits": [
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1003",
				"_score": 1,
				"_source": {
					"nickname": "飞翔的巨鹰",
					"age": 20,
					"desc": "慕课网团队和导游坐飞机去海外旅游,去了新马泰和欧洲"
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1001",
				"_score": 1,
				"_source": {
					"nickname": "慕课网",
					"age": 18,
					"desc": "我在慕课网学习java和前端, 学习到了很多知识"
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1004",
				"_score": 1,
				"_source": {
					"nickname": "水中鱼",
					"age": 22,
					"desc": "昨天在学校的池塘里,看到有很多鱼在游泳,然后就去慕课网上课了"
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1009",
				"_score": 1,
				"_source": {
					"nickname": "骚年轮",
					"age": 22,
					"desc": "骚年在大学毕业后,考研究生去了"
				}
			}
		]
	}
}

3.1.2可视化查询

3.2 对所查询的字段进行分词查找 match

3.2.1 dsl查询

返回4条数据,如下,全词匹配:慕、课、网、慕课、课网、慕课网。(之前在自定义词库里添加的)

{
	"took": 7,
	"timed_out": false,
	"_shards": {
		"total": 3,
		"successful": 3,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 4,
			"relation": "eq"
		},
		"max_score": 7.372511,
		"hits": [
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1001",
				"_score": 7.372511,
				"_source": {
					"nickname": "慕课网",
					"age": 18,
					"desc": "我在慕课网学习java和前端, 学习到了很多知识"
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1003",
				"_score": 6.846202,
				"_source": {
					"nickname": "飞翔的巨鹰",
					"age": 20,
					"desc": "慕课网团队和导游坐飞机去海外旅游,去了新马泰和欧洲"
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1004",
				"_score": 6.478179,
				"_source": {
					"nickname": "水中鱼",
					"age": 22,
					"desc": "昨天在学校的池塘里,看到有很多鱼在游泳,然后就去慕课网上课了"
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1006",
				"_score": 0.88025683,
				"_source": {
					"nickname": "我叫小慕",
					"age": 19,
					"desc": "我叫凌云慕,今年20岁,是一名律师,我在奇䯲星球做演讲"
				}
			}
		]
	}
}

3.2.2可视化查询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@所谓伊人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值