Relevation on wildcard results and wildcard speed


(Michael) #1

Hi guys!
I want to do something like this.
When I search for example on field first_name by wildcard "A" I want
to see my result sortable like this

Andrew
Frank
Michael
Brenda

Can I do this by the naitive tools of elastic search?

And second question

I have some not_analyzed string fields, and I try to search by this
fields on the 500 000 items on ES, and I have 2 second on my computer
that is not realy fast
What I need to do, to make it faster?


(Shay Banon) #2

wildcard searches are going to be slow, especially when doing leading wildcards. You have several options:

  1. Use text_phrase_prefix query (new in 0.16.1), where you can control the number of max_expansions to reduce the time it takes to query.
  2. Use ngrams to try and provide different type of suggestions. That will need to be done by creating an analyzer for that, and defining it in the mappings. And then do a simple text query (both index text and search text will be analyzed and "ngrammed").
    On Tuesday, May 24, 2011 at 9:32 PM, Michael wrote:

Hi guys!
I want to do something like this.
When I search for example on field first_name by wildcard "A" I want
to see my result sortable like this

Andrew
Frank
Michael
Brenda

Can I do this by the naitive tools of elastic search?

And second question

I have some not_analyzed string fields, and I try to search by this
fields on the 500 000 items on ES, and I have 2 second on my computer
that is not realy fast
What I need to do, to make it faster?


(Andrew Degtiariov) #3

On Tue, May 24, 2011 at 11:25 PM, Shay Banon
shay.banon@elasticsearch.comwrote:

wildcard searches are going to be slow, especially when doing leading
wildcards. You have several options:

  1. Use text_phrase_prefix query (new in 0.16.1), where you can control the
    number of max_expansions to reduce the time it takes to query.
  2. Use ngrams to try and provide different type of suggestions. That will
    need to be done by creating an analyzer for that, and defining it in the
    mappings. And then do a simple text query (both index text and search text
    will be analyzed and "ngrammed").

Does text_phrase_prefix query works on not analyzed fields? My tests show it
work like prefix when field is not analyzed:

For example:
The query {'query': {'text_phrase_prefix': {'fields.name': {'query': 'yuriy
os' } } } matched document with fields.name 'yuriy ostapyuk'

But the query {'query': {'text_phrase_prefix': {'fields.name': {'query':
'os' } } } doesn't match any documents.

--
Andrew Degtyarev
DA-RIPE


(Shay Banon) #4

Yes, it works on non analyzed fields, but then, the entire content is checked against as a single term. so you need to provide a full prefix. If you want the text to be "broken" down into more granular terms, then you need to have it analyzed.

On Friday, May 27, 2011 at 4:30 PM, Andrew Degtyarev wrote:

On Tue, May 24, 2011 at 11:25 PM, Shay Banon <shay.banon@elasticsearch.com (mailto:shay.banon@elasticsearch.com)> wrote:

wildcard searches are going to be slow, especially when doing leading wildcards. You have several options:

  1. Use text_phrase_prefix query (new in 0.16.1), where you can control the number of max_expansions to reduce the time it takes to query.
  2. Use ngrams to try and provide different type of suggestions. That will need to be done by creating an analyzer for that, and defining it in the mappings. And then do a simple text query (both index text and search text will be analyzed and "ngrammed").

Does text_phrase_prefix query works on not analyzed fields? My tests show it work like prefix when field is not analyzed:

For example:
The query {'query': {'text_phrase_prefix': {'fields.name (http://fields.name)': {'query': 'yuriy os' } } } matched document with fields.name (http://fields.name) 'yuriy ostapyuk'

But the query {'query': {'text_phrase_prefix': {'fields.name (http://fields.name)': {'query': 'os' } } } doesn't match any documents.

--
Andrew Degtyarev
DA-RIPE


(Andrew Degtiariov) #5

On Fri, May 27, 2011 at 4:32 PM, Shay Banon shay.banon@elasticsearch.comwrote:

Yes, it works on non analyzed fields, but then, the entire content is
checked against as a single term. so you need to provide a full prefix. If
you want the text to be "broken" down into more granular terms, then you
need to have it analyzed.

Hm...
Don't understand. Could you explain about "full prefix"?

On Friday, May 27, 2011 at 4:30 PM, Andrew Degtyarev wrote:

On Tue, May 24, 2011 at 11:25 PM, Shay Banon <shay.banon@elasticsearch.com

wrote:

wildcard searches are going to be slow, especially when doing leading
wildcards. You have several options:

  1. Use text_phrase_prefix query (new in 0.16.1), where you can control the
    number of max_expansions to reduce the time it takes to query.
  2. Use ngrams to try and provide different type of suggestions. That will
    need to be done by creating an analyzer for that, and defining it in the
    mappings. And then do a simple text query (both index text and search text
    will be analyzed and "ngrammed").

Does text_phrase_prefix query works on not analyzed fields? My tests show
it work like prefix when field is not analyzed:

For example:
The query {'query': {'text_phrase_prefix': {'fields.name': {'query':
'yuriy os' } } } matched document with fields.name 'yuriy ostapyuk'

But the query {'query': {'text_phrase_prefix': {'fields.name': {'query':
'os' } } } doesn't match any documents.

--
Andrew Degtyarev
DA-RIPE

--
Andrew Degtyarev
DA-RIPE


(Shay Banon) #6

Since the entire content of the field is a single token (not indexed), then a prefix will only work on all of it. Exactly the behavior you saw.

On Friday, May 27, 2011 at 5:20 PM, Andrew Degtyarev wrote:

On Fri, May 27, 2011 at 4:32 PM, Shay Banon <shay.banon@elasticsearch.com (mailto:shay.banon@elasticsearch.com)> wrote:

Yes, it works on non analyzed fields, but then, the entire content is checked against as a single term. so you need to provide a full prefix. If you want the text to be "broken" down into more granular terms, then you need to have it analyzed.

Hm...
Don't understand. Could you explain about "full prefix"?

On Friday, May 27, 2011 at 4:30 PM, Andrew Degtyarev wrote:

On Tue, May 24, 2011 at 11:25 PM, Shay Banon <shay.banon@elasticsearch.com (mailto:shay.banon@elasticsearch.com)> wrote:

wildcard searches are going to be slow, especially when doing leading wildcards. You have several options:

  1. Use text_phrase_prefix query (new in 0.16.1), where you can control the number of max_expansions to reduce the time it takes to query.
  2. Use ngrams to try and provide different type of suggestions. That will need to be done by creating an analyzer for that, and defining it in the mappings. And then do a simple text query (both index text and search text will be analyzed and "ngrammed").

Does text_phrase_prefix query works on not analyzed fields? My tests show it work like prefix when field is not analyzed:

For example:
The query {'query': {'text_phrase_prefix': {'fields.name (http://fields.name)': {'query': 'yuriy os' } } } matched document with fields.name (http://fields.name) 'yuriy ostapyuk'

But the query {'query': {'text_phrase_prefix': {'fields.name (http://fields.name)': {'query': 'os' } } } doesn't match any documents.

--
Andrew Degtyarev
DA-RIPE

--
Andrew Degtyarev
DA-RIPE


(system) #7