What are the best ways to find near phrases? How to combine them to find near to nearesr near? ))

How to find nearest near.

“query” : {
“query_string”: {
“query”: “"field korean"~10”,
“fields” : [“message.stemmed”],
“default_operator”: “AND”

It finds all strings that contain words field and korean with slope of 10 words.
But what if want to make more complex query, that finds after previoues pfrase?

field korean(slope 10) - and after this another phrase not farther than 5 words.
For instance (“infantry battle”)
Is it even possible using query_string?
So slope after phrase? Ho to implement it?
Can you give some examples?

I’m pretty sure you can’t do this with query_string, because you can’t have nested phrases: to have a phrase with a slop between two sub-phrases.

You might be able to do this with Span Near, where clauses of the main Span Near can be other Span Near sub-queries. The problem is that spans are not analyzed, so you’ll have to deal with analysis somehow (embedded Lucene/OpenSearch? Analyze API?) before building the query.

Are there any examples?
I haven’t found any.

In the link above you’ll see examples of using span_near. There, the clauses are span_term - looking for individual terms near each other. Like a phrase. But the clauses can also be span_near as well.

What is the difference between Span queries and intervals?

And what internal query will “query_string” “query”: ““field korean”~10” be converted to?

Intervals seem to wrap span queries in the sense that they can be analyzed. Now that you mention them, it might be a better idea to start there :slight_smile:

That query_string query you mention will be translated to a phrase with a slop, AFAIK.