Querying Flashcards Preview

Udemy: Elastisearch Masterclass > Querying > Flashcards

Flashcards in Querying Deck (16):
1

What are the two major search contexts?

Query and filter context

2

Search all for a index

GET /index/_search
{
"query": {
"match_all": {}
}
}

3

Search for a value in a field

GET /courses/_search
{
"query": {
"match": {"name": "250"}
}
}

4

To query for a mapping that exists

GET /courses/_search
{
"query": {
"exists": {"field": "professor.email"}
}
}
Note this will collect empty strings

5

To query for multiple matches

GET /courses/_search
{
"query": {
"bool": {
{"must": [
{"match": {"name": "joe"},
{"match": {"room": "212"}
]
}
}
}
Note this will collect empty strings

6

Clauses in queries

must
must_not
should (adds a benefit)
minimum_should_match
multi_match
match_phrase
range

7

minimum_should_match

Since must and must_not are prioritized over should. Minimum should match accepts an integer for the number of shoulds that it has to match

8

multi_match

search many fields
{
"query": {
"multi_match": {
"fields": {"name", "professor.department"},
"query": "Accounting 101"
}
}
}

9

match_phrase

matches a full phrase

10

filter must be wrapped in

The query bool field

11

Biggest difference you'll see between query and filter

There is no relevancy score in filter
Filter is faster, use it if you don't want to do scoring
Uses the same syntax

12

To boost a something for search

Add a ^ to the field in a multi_match. It defaults to 2 but you can add ^5 depending on importance

13

To bulk POST

POST /vehicles/cars/_bulk
{ "index": {}}
{ "price" : 10000, "color" : "white", "make" : "honda", "sold" : "2016-10-28", "condition": "okay"}
{ "index": {}}
{ "price" : 20000, "color" : "white", "make" : "honda", "sold" : "2016-11-05", "condition": "new" }

14

To set how many documents to return

In the GET set "size": 5

15

To sort

In the GET set sort
"sort": { [
{ "price": {"order": "desc"}
]}

16

To get a count

GET /index/type/_count