I have an Elasticsearch index structured as follows:
Example entry:
{
'ID': '1',
'creator': 'Sam',
'instance': 'court of cassation',
'text': [
{
'depth': 0,
'role': 'introduction',
'caseText': ['27', 'october', 'decision', 'of', 'the', 'high', 'court', 'in', 'the', 'case', 'of']
'ngrams': ['in_the', 'case_of']
},
{
'depth': 1,
'role': 'decision',
'caseText': ['we', 'decide', 'a', 'sentence', 'of', 'three', 'weeks']
'ngrams': ['three_weeks']
}]
}
In my example, I'm facing the problem that 'high court' is not registered as an ngram, so I want to perform a search where I force high
and court
to be next to each other in the caseText
-field
I tried doing it using the span_near
query, but without result:
{
'query': {
'span_near': {
'clauses': [
'span_term': { 'text.caseText': 'high'}},
'span_term': { 'text.caseText': 'court'}},
],
'slop': 0,
'in_order': True
}
}
}
I'm afraid my understanding of the span_near
query is somehow wrong, but I really need this to work. Any help is greatly appreciated!