'How to write ES search queries for complex documents structure?
I have the following documents and structure:
Document 1:
{
'id': '1',
'data': {
'parents': [],
'people': []
}
Document 2:
{
'id': '2',
'data': {
'parents': ["one", "two"],
'people': [{'relationship': 'boss', 'ids': ['1']}, {'relationship': 'friends', 'ids': ['1']}]
}
Document 3:
{
'id': '3',
'data': {
'parents': ["one", "two"],
'people': [{'relationship': 'boss', 'ids': ['1', '2']}, {'relationship': 'friends', 'ids': ['1', '2']}]
}
}
I want to delete a document given an id and then delete any relationships with document in other documents.
So given id = '1', document 1 is deleted, and document 2 and 3's relationship entires that include '1' are updated to not include '1' anymore; so after document 1 is deleted, we have the following:
Document 2:
{
'id': '2',
'data': {
'parents': ["one", "two"],
'people': []
}
Document 3:
{
'id': '3',
'data': {
'parents': ["one", "two"],
'people': [{'relationship': 'boss', 'ids': ['2']}, {'relationship': 'friends', 'ids': ['2']}]
}
}
I am struggling writing the ES queries because the document's structure is a complex one;
What I have tried so far are the following:
{ 'query': { 'match': { 'id.keyword': '1' } } }
{ 'terms': {data.people.ids.keyword: ['1'], 'minimum_should_match': 1 } }
but they do not work, nor do they throw an error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
