Elasticsearch
1.query string search
1.1.搜索全部
// 1.
GET http://ip:9200/test/test/_search
结果:
{
"took": 86, # 耗费的时间:ms
"timed_out": false, # 是否超时
"_shards": { # 数据存储在5个主分片上
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": { # 匹配结果
"total": 3, # 查询到三个document
"max_score": 1, # 相关度的匹配分数:分数越高越相关
"hits": [
{
"_index": "test", # 索引 index
"_type": "test", # type
"_id": "2", # id:唯一
"_score": 1, # 相关度的匹配分数:分数越高越相关
"_source": { # 存储的json数据
"first_name": "小翠", # field
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
1.2.以about字段中含有climbing字符查询并根据age字段降序排列 可以多个排序,用逗号分隔:
// 2.
GET http://ip:9200/test/test/_search?q=about:climbing&sort=age:desc,price:desc
GET http://ip:9200/test/test/_search?q=about:climbing&sort=age:desc
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": null,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [ #排序字段的值
25
]
},
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
2.query DSL
2.1.搜索全部
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match_all":{}
}
}
结果:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 1,
"_source": {
"first_name": "小雪",
"last_name": "xiaoxue",
"age": 20,
"about": "climbing",
"interests": [
"dancing",
"music"
]
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
2.2.以about字段中含有climbing字符查询并根据age字段降序排列 可以多个排序,用逗号分隔
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match":{
"about":"climbing"
}
},
"sort":[
{
"age":"desc"
}
]
}

结果:
{
"took": 115,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": null,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": null,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
25
]
},
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": null,
"_source": {
"first_name": "小雪",
"last_name": "xiaoxue",
"age": 20,
"about": "climbing",
"interests": [
"dancing",
"music"
]
},
"sort": [
20
]
},
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
2.3. 分页数据
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match_all":{} # 查询所有
},
"from":0, # 从第几条数据开始 0:第一条
"size":1 # 展示几条数据
}
1
2
3
4
5
6
7
8
9
10
2.4.只展示指定的filed
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match_all":{}
},
"_source":[
"first_name",
"age"
]
}

结果:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 1,
"_source": {
"first_name": "小雪",
"age": 20
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
3.query filter
3.1.多个查询条件:about字段必须包含"climbing";age大于20岁
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"bool":{
"must":{
"match":{
"about":"climbing"
}
},
"filter":{
"range":{
"age":{
"gt":20
}
}
}
}
}
}

结果
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.26742277,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.26742277,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
3.2. 多个查询条件:must、 should、 must_not
POST http://ip:9200/test/test/_search
{
"query":{
"bool":{
"must":{ # 必须匹配
"match":{
"first_name":"小翠"
}
},
"should":{ # 可以匹配,也可以不匹配
"match":{
"last_name": "xue"
}
},
"must_not":{ # 必须不匹配
"match":{
"last_name": "cui"
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
4.full-test search
4.1.全文检索
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match":{
"about":"go climbing"
}
}
}
分析:es将about这个filed拆解成每个词(term),建立倒排索引,每个term对应相应的document_id
结果:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 7,
"max_score": 0.7447149,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.61562645,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 0.61562645,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "5",
"_score": 0.2876821,
"_source": {
"first_name": "花花",
"last_name": "huahau",
"age": 16,
"price": 20000,
"about": "climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "7",
"_score": 0.25759193,
"_source": {
"about": "go"
}
},
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 0.25759193,
"_source": {
"first_name": "小雪",
"last_name": "xiaoxue",
"age": 20,
"about": "climbing",
"interests": [
"dancing",
"music"
]
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
4.2.短语搜索:匹配短语
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match_phrase":{
"about":"rock climbing"
}
}
}

结果:
{
"took": 20,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0.9748371,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.9748371,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 0.6156264,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
5.highlight search
5.1.关键字高亮
// 1.
语法:
{
"query":{
"match":{
"about":"climbing" # 关键字
}
},
"highlight":{
"fields":{
"about":{} # 字段
}
}
}

结果:
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 6,
"max_score": 0.48741856,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.48741856,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"highlight": {
"about": [
"I love to go rock <em>climbing</em>" # <em> 标签html中高亮显示
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": 0.37235746,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"highlight": {
"about": [
"I love to go rock <em>climbing</em>"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": 0.37235746,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"highlight": {
"about": [
"I love to go rock <em>climbing</em>"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "5",
"_score": 0.2876821,
"_source": {
"first_name": "花花",
"last_name": "huahau",
"age": 16,
"price": 20000,
"about": "climbing",
"interests": [
"sports",
"music"
]
},
"highlight": {
"about": [
"<em>climbing</em>"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 0.25759193,
"_source": {
"first_name": "小雪",
"last_name": "xiaoxue",
"age": 20,
"about": "climbing",
"interests": [
"dancing",
"music"
]
},
"highlight": {
"about": [
"<em>climbing</em>"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 0.12820786,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"highlight": {
"about": [
"I love to go rock <em>climbing</em>"
]
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

---------------------

Elasticsearch学习(二)————搜索的更多相关文章

  1. Elasticsearch 学习二(请求流程).

    一.写入数据 1.ES 的任意节点都可以作为协调(Coordinating)节点接受请求(包括新建.索引或者删除请求),每个节点都知道集群中任一文档位置: 2.协调节点会通过 routing 字段计算 ...

  2. Elasticsearch学习之深入搜索二 --- 搜索底层原理剖析

    1. 普通match如何转换为term+should { "match": { "title": "java elasticsearch"} ...

  3. ElasticSearch 学习记录之ES高亮搜索

    高亮搜索 ES 通过在查询的时候可以在查询之后的字段数据加上html 标签字段,使文档在在web 界面上显示的时候是由颜色或者字体格式的 GET /product/_search { "si ...

  4. 【Elasticsearch学习】文档搜索全过程

    在ES执行分布式搜索时,分布式搜索操作需要分散到所有相关分片,若一个索引有3个主分片,每个主分片有一个副本分片,那么搜索请求会在这6个分片中随机选择3个分片,这3个分片有可能是主分片也可能是副本分片, ...

  5. Elasticsearch学习之深入搜索一 --- 提高查询的精准度

    1. 为帖子增加标题字段 POST /forum/article/_bulk { "} } { "doc" : {"title" : "th ...

  6. ElasticSearch7.3学习(二十六)----搜索(Search)参数总结、结果跳跃(bouncing results)问题解析

    1.preference 首先引入一个bouncing results问题,两个document排序,field值相同:不同的shard上,可能排序不同:每次请求轮询打到不同的replica shar ...

  7. elasticsearch的rest搜索--- 查询

    目录: 一.针对这次装B 的解释 二.下载,安装插件elasticsearch-1.7.0   三.索引的mapping 四. 查询 五.对于相关度的大牛的文档 四. 查询 1. 查询的官网的文档   ...

  8. Elasticsearch学习总结 (Centos7下Elasticsearch集群部署记录)

    一.  ElasticSearch简单介绍 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticse ...

  9. elasticsearch实现网站搜索

    使用elasticsearch 实现网站搜索,可以支持商品搜索,筛选项过滤搜索 ,价格排序, 打分 筛选项聚合,还有其他综合排序 后续推出搜索人工干预排序,根据销量,好评率,售卖率 进行全方位的搜索实 ...

  10. ElasticSearch(二):文档的基本CRUD与批量操作

    ElasticSearch(二):文档的基本CRUD与批量操作 学习课程链接<Elasticsearch核心技术与实战> Create 文档 支持自动生成文档_id和指定文档_id两种方式 ...

随机推荐

  1. Burpsuite实验(二)

    一.这次我们使用一下burpsuite的代理拦截功能. 图中的proxy是代理的选项,其中intercept是拦截的功能,在浏览器中请求的包,都经过它. 这是打开拦截时候的状态.forward是通过此 ...

  2. JavaScript-Tool:Ext JS

    ylbtech-JavaScript-Tool:Ext JS extjs是一种软件.自动生成行号,支持checkbox全选,动态选择显示哪些列,支持本地以及远程分页,可以对单元格按照自己的想法进行渲染 ...

  3. mounted

    注意 mounted 不会承诺所有的子组件也都一起被挂载.如果你希望等到整个视图都渲染完毕,可以用 vm.$nextTick 替换掉 mounted: mounted: function () { t ...

  4. View Controller Programming Guide for iOS---(五)---Resource Management in View Controllers

    Resource Management in View Controllers View controllers are an essential part of managing your app’ ...

  5. linux下svn的建库以及相关配置

    1.安装svn软件 yum install subversion -y 2.建立库的根目录,此目录下为所有库的根目录(路径为:/home/svn-server/) ,然后进入此目录 mkdir /ho ...

  6. C++ STL自学总结,仅供参考

    本文内容,为博主在网上看到资料总结整合而来 一.stl格式简介 .stl文件是在计算机图形应用系统,来表示封闭的面或者体,用来表示三角形网格的一种文件格式.为STereo Lithography的缩写 ...

  7. 看鸟哥的Linux私房菜的一些命令自我总结(一)

    -显示目前所支持的语言  echo &LANG -修改语言成为英文系统  LANG=en_US -显示日历的命令 cal [[month] year] -惯用关机命令 shutdown 参数: ...

  8. 洛谷 - P2774 - 方格取数问题 - 二分图最大独立点集 - 最小割

    https://www.luogu.org/problemnew/show/P2774 把两个相邻的节点连边,这些边就是要方便最小割割断其他边存在的,容量无穷. 这种类似的问题的话,把二分图的一部分( ...

  9. (水题)洛谷 - P1308 - 统计单词数

    https://www.luogu.org/problemnew/show/P1308 简单哈希一下判断,练练手. 注意fgets()的用法,第一个参数传存储位置,第二个参数传内存上限,第三个传std ...

  10. 让VS2010也支持html5和css3语法验证

    让VS2010也支持html5和css3语法验证 步骤: 首先打开VS2010或者可自行下载均可,我这里是利用VS的扩展器 弹出如下画面,然后选在,联机库,在右上角输入css3,即可看到下面,然后选中 ...