This repository was archived by the owner on Sep 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy path05_Multiple_query_strings.json
132 lines (125 loc) · 2.24 KB
/
05_Multiple_query_strings.json
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
# Delete the `my_index` index
DELETE /my_index
# Create `my_index` with a single primary shard
PUT /my_index
{ "settings": { "number_of_shards": 1 }}
# Index some example docs
PUT /my_index/book/1
{
"title": "War and Peace",
"author": "Leo Tolstoy",
"translator": [
"Louise Maude",
"Aylmer Maude"
]
}
PUT /my_index/book/2
{
"title": "War and Peace",
"author": "Leo Tolstoy",
"translator": "Constance Garnett"
}
PUT /my_index/book/3
{
"title": "War and Peace",
"author": "Leo Tolstoy",
"translator": "Ann Dunnigan"
}
# Search for "War and Peace" by "Leo Tolstoy"
GET /my_index/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "War and Peace"
}
},
{
"match": {
"author": "Leo Tolstoy"
}
}
]
}
}
}
# Prefer certain translators
GET /my_index/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "War and Peace"
}
},
{
"match": {
"author": "Leo Tolstoy"
}
},
{
"bool": {
"should": [
{
"match": {
"translator": "Constance Garnett"
}
},
{
"match": {
"translator": "Louise Maude"
}
}
]
}
}
]
}
}
}
# Boost title and author over translator
GET /my_index/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "War and Peace",
"boost": 2
}
}
},
{
"match": {
"author": {
"query": "Leo Tolstoy",
"boost": 2
}
}
},
{
"bool": {
"should": [
{
"match": {
"translator": "Constance Garnett"
}
},
{
"match": {
"translator": "Louise Maude"
}
}
]
}
}
]
}
}
}