Index Creation and Document Addition Flashcards

1
Q

Index Creation

A

PUT /my_index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Add Documents

A

POST /my_index/_doc/1
{
“name”: “John Doe”,
“age”: 30,
“location”: “New York”
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Basic Search

A

GET /my_index/_search
{
“query”: {
“match”: {
“name”: “John”
}
}
}

This will return documents in my_index where the name field matches “John”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Match Query

A

GET /my_index/_search
{
“query”: {
“match”: {
“content”: “Elasticsearch tutorial”
}
}
}

The above query searches for documents where the content field contains terms related to “Elasticsearch tutorial”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Term Query

A

GET /my_index/_search
{
“query”: {
“term”: {
“status”: “published”
}
}
}

This example searches for documents where the status field exactly matches “published”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Multi Match Query

A

GET /my_index/_search
{
“query”: {
“multi_match”: {
“query”: “Elasticsearch tutorial”,
“fields”: [“title”, “content”, “tags”]
}
}
}
This query searches for documents where “Elasticsearch tutorial” appears in any of the specified fields (title, content, or tags).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Match Phrase Query

A

GET /my_index/_search
{
“query”: {
“match_phrase”: {
“content”: “quick brown fox”
}
}
}

This query finds documents where the phrase “quick brown fox” appears in the content field, in that exact order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Match All Query

A

GET /my_index/_search
{
“query”: {
“match_all”: {}
}
}

The match_all query returns all documents in the index. It is often used as a starting point for filtering or sorting the entire data set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Range Query

A

GET /my_index/_search
{
“query”: {
“range”: {
“publish_date”: {
“gte”: “2023-01-01”,
“lte”: “2023-12-31”
}
}
}
}
This query searches for documents where the publish_date falls within the specified range.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Boolean Search

A

GET /my_index/_search
{
“query”: {
“bool”: {
“must”: [
{ “match”: { “title”: “Elasticsearch” } }
],
“must_not”: [
{ “term”: { “status”: “archived” } }
],
“should”: [
{ “match”: { “tags”: “search” } }
]
}
}
}

In this example:
The must clause requires the title field to contain “Elasticsearch”.
The must_not clause excludes documents where the status is “archived”.
The should clause boosts the relevance of documents that also have “search” in the tags field.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Wildcard Query

A

The wildcard query allows using wildcard characters like * (matches zero or more characters) and ? (matches a single character).
{
“query”: {
“wildcard”: {
“username”: “user*”
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Prefix Query

A

{
“query”: {
“prefix”: {
“product”: “ela”
}
}
}

This query finds documents where the product field starts with “ela” (e.g., “elastic”, “elaborate”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Exists

A

{
“query”: {
“exists”: {
“field”: “tags”
}
}
}

This query retrieves documents that have a non-null tags field.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Fuzzy Query

A

{
“query”: {
“fuzzy”: {
“name”: {
“value”: “elastik”,
“fuzziness”: 2
}
}
}
}

This query finds documents where the name field is similar to “elastik” with up to two character changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly