Combinining proximity search and other operators for complex entities


I need help with a query in ES. I'm doing a Google-type search engine with ES (so I'm using query_string queries with the queries directly extracted from the search text box that the user gets to write in), and it has to have a particular syntax for the queries:

((black or afro$ or African$) adj2 (kid or kids or infant$ or pediatric$ or paedriatic$ or child$ or neonatal$ or newborn$ or adolescen$ or girl$ or boy$)).ti,ab

$ is the wildcard * in ES
or and the different parenthesis work as one should expect
.ti,ab is a way to represent the fields to search (fi for "field" and ab for "abstract")

These 3 previous requirements are fulfilled with ES syntax in the query string queries. However, adj2 refers to proximity search, where the result of preceding and following clauses (both grouped with parentheses in this case) have to have a word distance of 2 maximum. In the query string queries, proximity uses the "abc def"~2 syntax, but it only works for quoted phrases. In my example, I do not have quoted phrases, but complex entities that can have AND/OR, wildcards and parentheses, which the ES syntax can't process.

So given that limitation, how can I achieve what I want? I also tried a bit with span_near (although I'd prefer using the string query syntax, which can be directly input by the user in the textbox), but again the span clauses are not easy to combine with the different operators and I'm not sure that what I want is even possible.

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.