Search - Joining Queries Flashcards

1
Q

What is?

A

In Elasticsearch, joining queries allow you to relate documents to one another, similar to join operations in relational databases. However, because Elasticsearch is a distributed, document-oriented database, it doesn’t support traditional joins between unrelated documents across indices.

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

Nested Query

A

Suppose you have documents for products with an array of reviews, each containing a reviewer and rating. The nested query lets you search for specific review criteria.

{
“query”: {
“nested”: {
“path”: “reviews”,
“query”: {
“bool”: {
“must”: [
{ “match”: { “reviews.reviewer”: “Alice” } },
{ “range”: { “reviews.rating”: { “gte”: 4 } } }
]
}
}
}
}
}

Finds products with a reviews object where the reviewer is “Alice” and the rating is at least 4.

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

has parent query

A

This requires a parent-child relationship, where documents are stored with a join field, associating child documents with their parents.

Assume you have article (parent) and comment (child) documents with a join field linking them.

{
“query”: {
“has_parent”: {
“parent_type”: “article”,
“query”: {
“match”: { “title”: “Elasticsearch” }
}
}
}
}

Finds comment documents where the parent article document has the title containing “Elasticsearch”.

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

Has Child Query

A

This example finds article documents with related comment children that have a rating of 5.

{
“query”: {
“has_child”: {
“type”: “comment”,
“query”: {
“match”: { “rating”: 5 }
}
}
}
}

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

Parent ID Query

A

Finding all child documents for a particular parent document.
{
“query”: {
“parent_id”: {
“type”: “comment”,
“id”: “article123”
}
}
}

Returns comment documents that have article123 as their parent.

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