Search anchored at beginning/end of string with slop

I have a search case where it's desirable to anchor the query at the
beginning and end of the string but allow slop in the middle. For example,
I have field "friends" with a list of names in it as strings:

"A User"
"B User"
"A B User"
"C User D"
"C User"

The user needs to be able to enter a query like "A User" and have it match
"A User" and "A B User" but not others (the reason for this is that they
typically get the first initial correct and last name but may not know any
middle initials). A search for "C User" should not match "C User D". This
is in an application I'm porting from solr to Elasticsearch, in solr I had
written a span query plugin to construct these and then surrounded each
name with tokens: "^^^ A User $$$" so I could anchor span terms on the
beginning and end of the strings.

I'm wondering what the translation of this is to elasticsearch, any help
greatly appreciated.

Thanks,
Paul

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Paul,
have a look at the elasticsearch query DSLhttp://www.elasticsearch.org/guide/reference/query-dsl/,
which exposes the lucene span queries as well. You combine them pretty much
as you would do with lucene, but you have to express them in json format.
In your case I'd have a look mainly at the span first queryhttp://www.elasticsearch.org/guide/reference/query-dsl/span-first-query/
, span near queryhttp://www.elasticsearch.org/guide/reference/query-dsl/span-near-query/.
Also note that with span queries you have to use a span term queryhttp://www.elasticsearch.org/guide/reference/query-dsl/span-term-query/ to
provide the term, which is essentially a basic term query that takes into
account positions too.

Let me know how it went and don't hesitate to ask if you need any further
information

Cheers
Luca

On Thursday, August 22, 2013 9:20:58 PM UTC+2, Paul Dlug wrote:

I have a search case where it's desirable to anchor the query at the
beginning and end of the string but allow slop in the middle. For example,
I have field "friends" with a list of names in it as strings:

"A User"
"B User"
"A B User"
"C User D"
"C User"

The user needs to be able to enter a query like "A User" and have it match
"A User" and "A B User" but not others (the reason for this is that they
typically get the first initial correct and last name but may not know any
middle initials). A search for "C User" should not match "C User D". This
is in an application I'm porting from solr to Elasticsearch, in solr I had
written a span query plugin to construct these and then surrounded each
name with tokens: "^^^ A User $$$" so I could anchor span terms on the
beginning and end of the strings.

I'm wondering what the translation of this is to elasticsearch, any help
greatly appreciated.

Thanks,
Paul

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.