ElasticSearch usage

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

#Getting number of documents in books index
GET books/_count

# Turn off the source
GET books/_search
{
"_source": false,
"query": {
"ids": {
"values": [1,2,3]
}
}
}

GET books/_search
{
"query": {
"prefix": {
"author": "josh"
}
}
}

GET books/_search
{
"query": {
"match": {
"author": {
"query": "Joshua Herbert",
"operator": "AND"
}
}
}
}

# Searching across multiple fields using multi_match query
GET books/_search
{
"query": {
"multi_match": {
"query": "Java",
"fields": ["title","synopsis"]
}
}
}
# Boosting scores
GET books/_search
{
"query": {
"multi_match": {
"query": "Java",
"fields": ["title^3","synopsis"]
}
}
}
# Match Phrase query with slop 1
GET books/_search
{
"query": {
"match_phrase": {
"synopsis": {
"query": "must-have book every Java programmer",
"slop": 1
}
}
}
}

#Fuzzy query (forgiving spelling mistakes)
GET books/_search
{
"query": {
"fuzzy": {
"title": {
"value": "kava",
"fuzziness": 1
}
}
}
}

GET books/_search
{
"query": {
"match_phrase_prefix": {
"title": "Java co"
}
}
}

# Getting third edition books using term query
GET books/_search
{

"query": {
"term": {
"edition": {
"value": 3
}
}
}
}

# Range query
GET books/_search
{
"query": {
"range": {
"amazon_rating": {
"gte": 4.5,
"lte": 5
}
}
}
}