Prefix question


(Valentin Pletzer) #1

Hi,

I have a question about the use of the prefix filter. Suppose I have
two records with a field "phrase" which have the values "apple banana"
and "banana cherry" and lets assume I want to make a prefix-search for
"b" on phrase (autocompletion). What do I have to do, to only get the
record "banana cherry" but not the record "apple banana"?

Right now I use the following filter-query:

{
"filter": {
"bool": {
"must": [
{
"prefix": {
"phrase": "z"
}
}
]
}
}
}


(Otis Gospodnetić) #2

Hi Valentin,

You need to make sure your fields are not broken into tokens on space,
but just "left edge n-gramed".

Otis

Sematext is hiring ElasticSearch / Solr developers --

On Jan 17, 11:13 am, Valentin plet...@gmail.com wrote:

Hi,

I have a question about the use of the prefix filter. Suppose I have
two records with a field "phrase" which have the values "apple banana"
and "banana cherry" and lets assume I want to make a prefix-search for
"b" on phrase (autocompletion). What do I have to do, to only get the
record "banana cherry" but not the record "apple banana"?

Right now I use the following filter-query:

{
"filter": {
"bool": {
"must": [
{
"prefix": {
"phrase": "z"
}
}
]
}
}

}


(Shay Banon) #3

Another option is to use text query with the phrase prefix option:
http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html.

On Wed, Jan 18, 2012 at 7:38 AM, Otis Gospodnetic <
otis.gospodnetic@gmail.com> wrote:

Hi Valentin,

You need to make sure your fields are not broken into tokens on space,
but just "left edge n-gramed".

Otis

Sematext is hiring ElasticSearch / Solr developers --
http://sematext.com/about/jobs.html

On Jan 17, 11:13 am, Valentin plet...@gmail.com wrote:

Hi,

I have a question about the use of the prefix filter. Suppose I have
two records with a field "phrase" which have the values "apple banana"
and "banana cherry" and lets assume I want to make a prefix-search for
"b" on phrase (autocompletion). What do I have to do, to only get the
record "banana cherry" but not the record "apple banana"?

Right now I use the following filter-query:

{
"filter": {
"bool": {
"must": [
{
"prefix": {
"phrase": "z"
}
}
]
}
}

}


(system) #4