Starts With Search


(davrob) #1

Hi,

Is there a way I can do a search that will automatically filter a
resultset like this which is on an Analysed field:

Search String = mo*:

Anti Money Laundering Analyst
Anti-Money Laundering CompOffi
Exec.Mgr.-Money Market Trading
Exec.Mgr.-Risk Modeling
Exp. Money Market Trader
Exp. Risk Modeler
Jun. Money Market Trader
Jun. Risk Modeler
Mgr.-Money Market Trading
Mgr.-Risk Modeling
Modeling Manager
Modeller
Money Market Dealer
Money Market Trader
Porter/Mover
Risk Modeler
Sen. Money Market Trader
Sen. Risk Modeler
Sen.Mgr.-Money Market Trading
Sen.Mgr.-Risk Modeling
Teaml.2-Risk Modeling

To This:

Search String = mo*:

Modeling Manager
Modeller
Money Market Dealer
Money Market Trader

Best Regards,

David.


(Clinton Gormley) #2

Hi David

Is there a way I can do a search that will automatically filter a
resultset like this which is on an Analysed field:

Search String = mo*:

Modeling Manager
Modeller
Money Market Dealer
Money Market Trader

The only query type which allows you to anchor a term to the beginning
of the field is span_first.

http://www.elasticsearch.org/guide/reference/query-dsl/span-first-query.html

Example usage:

Unfortunately, span-type queries only accept other span queries, so you
can't use the wildcard or prefix queries. In order to achieve what you
want, you'd need to find all the terms beginning with 'mo' in a separate
facets query, and create a span_term query for each term, all wrapped up
in a span_or query.

Not ideal I know...

the alternative would be to maintain another version of the field which
is not analyzed (or uses eg just the lower case token filter)

clint


(davrob) #3

Hi Clinton,

thanks for your suggestions, I was thinking of going with maintaining
an extra non-analysed field, since I have once already for sorting,
but trying this out in lucene, this type of field seems only to match
on the whole string:

e.g.

seach = Money* returns nothing

but

search = Money Market Dealer* would return "Money Market Dealer"

I could be wrong because this was a quick test I did on an in-memory
index I was creating in Lucene.

Best Regards,

David.

On Jun 9, 4:07 pm, Clinton Gormley clin...@iannounce.co.uk wrote:

Hi David

Is there a way I can do a search that will automatically filter a
resultset like this which is on an Analysed field:
Search String = mo*:

Modeling Manager
Modeller
Money Market Dealer
Money Market Trader

The only query type which allows you to anchor a term to the beginning
of the field is span_first.

http://www.elasticsearch.org/guide/reference/query-dsl/span-first-que...

Example usage:https://gist.github.com/1016898

Unfortunately, span-type queries only accept other span queries, so you
can't use the wildcard or prefix queries. In order to achieve what you
want, you'd need to find all the terms beginning with 'mo' in a separate
facets query, and create a span_term query for each term, all wrapped up
in a span_or query.

Not ideal I know...

the alternative would be to maintain another version of the field which
is not analyzed (or uses eg just the lower case token filter)

clint


(Clinton Gormley) #4

Hi David

thanks for your suggestions, I was thinking of going with maintaining
an extra non-analysed field, since I have once already for sorting,
but trying this out in lucene, this type of field seems only to match
on the whole string:

e.g.
seach = Money* returns nothing

but
search = Money Market Dealer* would return "Money Market Dealer"

This depends on:

  1. how your field is analyzed (or not)
  2. how you are doing your search

If you post a gist reproduction then we will be more able to help you.
(see http://www.elasticsearch.org/help )

clint


(system) #5