Question about TextQuery

I'm trying to understand how Text Query works. My goal is to make an
autocomplete/suggest feature. As below, I insert documents with the
"title" fields: "quick brown", "quick brown fox", "quiet brow" which
is analyzed with standard analyzer. I'm trying the Text Query with
phrase_prefix (http://www.elasticsearch.org/guide/reference/query-dsl/
text-query.html) pretty much exactly as described in the guide, but
I'm getting no hits with any query I'm using. For example, for "quick
brown" I would expect to see 2 hits: "quick brown" and "quick brown
fox".

What am I doing wrong? Is there a better analyzer/query setup I
should be using for an autocomplete kind of use case?

SET UP:
curl -XPOST localhost:9200/test -d '{
"mappings" : {
"document" : {
"properties" : {
"title" : { type: "string", analyzer : "standard" }
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/document/1' -d '{
"title" : "quick brown"
}'
curl -XPUT 'http://localhost:9200/test/document/2' -d '{
"title" : "quick brown fox"
}'
curl -XPUT 'http://localhost:9200/test/document/3' -d '{
"title" : "quiet brown"
}'

QUERY:
curl "localhost:9200/test/accounts/_search?pretty=true" -d '{
"query" : {
"text" : {
"message" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}
}'
=> No hits

Hi quain,
Your query is not correct. Should be:

curl "localhost:9200/test/document/_search?pretty=true" -d '{
"query" : {
"text" : {
"title" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}
}'

Cheers,
LTVP
On Feb 6, 2012, at 9:41 AM, quain wrote:

I'm trying to understand how Text Query works. My goal is to make an
autocomplete/suggest feature. As below, I insert documents with the
"title" fields: "quick brown", "quick brown fox", "quiet brow" which
is analyzed with standard analyzer. I'm trying the Text Query with
phrase_prefix (Elasticsearch Platform — Find real-time answers at scale | Elastic
text-query.html) pretty much exactly as described in the guide, but
I'm getting no hits with any query I'm using. For example, for "quick
brown" I would expect to see 2 hits: "quick brown" and "quick brown
fox".

What am I doing wrong? Is there a better analyzer/query setup I
should be using for an autocomplete kind of use case?

SET UP:
curl -XPOST localhost:9200/test -d '{
"mappings" : {
"document" : {
"properties" : {
"title" : { type: "string", analyzer : "standard" }
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/document/1' -d '{
"title" : "quick brown"
}'
curl -XPUT 'http://localhost:9200/test/document/2' -d '{
"title" : "quick brown fox"
}'
curl -XPUT 'http://localhost:9200/test/document/3' -d '{
"title" : "quiet brown"
}'

QUERY:
curl "localhost:9200/test/accounts/_search?pretty=true" -d '{
"query" : {
"text" : {
"message" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}
}'
=> No hits

Thanks! That was a silly mistake by me.

On Feb 5, 6:12 pm, Phu Le le.truong.vinh....@gmail.com wrote:

Hi quain,
Your query is not correct. Should be:

curl "localhost:9200/test/document/_search?pretty=true" -d '{
"query" : {
"text" : {
"title" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}

}'

Cheers,
LTVP
On Feb 6, 2012, at 9:41 AM, quain wrote:

I'm trying to understand how Text Query works. My goal is to make an
autocomplete/suggest feature. As below, I insert documents with the
"title" fields: "quick brown", "quick brown fox", "quiet brow" which
is analyzed with standard analyzer. I'm trying the Text Query with
phrase_prefix (Elasticsearch Platform — Find real-time answers at scale | Elastic
text-query.html) pretty much exactly as described in the guide, but
I'm getting no hits with any query I'm using. For example, for "quick
brown" I would expect to see 2 hits: "quick brown" and "quick brown
fox".

What am I doing wrong? Is there a better analyzer/query setup I
should be using for an autocomplete kind of use case?

SET UP:
curl -XPOST localhost:9200/test -d '{
"mappings" : {
"document" : {
"properties" : {
"title" : { type: "string", analyzer : "standard" }
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/document/1'-d '{
"title" : "quick brown"
}'
curl -XPUT 'http://localhost:9200/test/document/2'-d '{
"title" : "quick brown fox"
}'
curl -XPUT 'http://localhost:9200/test/document/3'-d '{
"title" : "quiet brown"
}'

QUERY:
curl "localhost:9200/test/accounts/_search?pretty=true" -d '{
"query" : {
"text" : {
"message" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}
}'
=> No hits

A followup question. Is there a way to prefer results that have the
phrase at the beginning? For example, if I'm searching for "quick
brown" to prefer "quick brown fox" over "fox quick brown", etc?

I am looking at the docs. and it seems like you can set a boost to
certain results. How can I structure something like this to do what I
want with a phrase_prefix text query?

Thanks!

On Feb 5, 6:54 pm, quain quaintena...@gmail.com wrote:

Thanks! That was a silly mistake by me.

On Feb 5, 6:12 pm, Phu Le le.truong.vinh....@gmail.com wrote:

Hi quain,
Your query is not correct. Should be:

curl "localhost:9200/test/document/_search?pretty=true" -d '{
"query" : {
"text" : {
"title" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}

}'

Cheers,
LTVP
On Feb 6, 2012, at 9:41 AM, quain wrote:

I'm trying to understand how Text Query works. My goal is to make an
autocomplete/suggest feature. As below, I insert documents with the
"title" fields: "quick brown", "quick brown fox", "quiet brow" which
is analyzed with standard analyzer. I'm trying the Text Query with
phrase_prefix (Elasticsearch Platform — Find real-time answers at scale | Elastic
text-query.html) pretty much exactly as described in the guide, but
I'm getting no hits with any query I'm using. For example, for "quick
brown" I would expect to see 2 hits: "quick brown" and "quick brown
fox".

What am I doing wrong? Is there a better analyzer/query setup I
should be using for an autocomplete kind of use case?

SET UP:
curl -XPOST localhost:9200/test -d '{
"mappings" : {
"document" : {
"properties" : {
"title" : { type: "string", analyzer : "standard" }
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/document/1'-d'{
"title" : "quick brown"
}'
curl -XPUT 'http://localhost:9200/test/document/2'-d'{
"title" : "quick brown fox"
}'
curl -XPUT 'http://localhost:9200/test/document/3'-d'{
"title" : "quiet brown"
}'

QUERY:
curl "localhost:9200/test/accounts/_search?pretty=true" -d '{
"query" : {
"text" : {
"message" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}
}'
=> No hits

There isn't an option to only restrict it to text at the beginning of the relevant field data.

On Tuesday, February 7, 2012 at 12:33 AM, quain wrote:

A followup question. Is there a way to prefer results that have the
phrase at the beginning? For example, if I'm searching for "quick
brown" to prefer "quick brown fox" over "fox quick brown", etc?

I am looking at the docs. and it seems like you can set a boost to
certain results. How can I structure something like this to do what I
want with a phrase_prefix text query?

Thanks!

On Feb 5, 6:54 pm, quain <quaintena...@gmail.com (http://gmail.com)> wrote:

Thanks! That was a silly mistake by me.

On Feb 5, 6:12 pm, Phu Le <le.truong.vinh....@gmail.com (http://gmail.com)> wrote:

Hi quain,
Your query is not correct. Should be:

curl "localhost:9200/test/document/_search?pretty=true" -d '{
"query" : {
"text" : {
"title" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}

}'

Cheers,
LTVP
On Feb 6, 2012, at 9:41 AM, quain wrote:

I'm trying to understand how Text Query works. My goal is to make an
autocomplete/suggest feature. As below, I insert documents with the
"title" fields: "quick brown", "quick brown fox", "quiet brow" which
is analyzed with standard analyzer. I'm trying the Text Query with
phrase_prefix (Elasticsearch Platform — Find real-time answers at scale | Elastic
text-query.html) pretty much exactly as described in the guide, but
I'm getting no hits with any query I'm using. For example, for "quick
brown" I would expect to see 2 hits: "quick brown" and "quick brown
fox".

What am I doing wrong? Is there a better analyzer/query setup I
should be using for an autocomplete kind of use case?

SET UP:
curl -XPOST localhost:9200/test -d '{
"mappings" : {
"document" : {
"properties" : {
"title" : { type: "string", analyzer : "standard" }
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/document/1'-d'{
"title" : "quick brown"
}'
curl -XPUT 'http://localhost:9200/test/document/2'-d'{
"title" : "quick brown fox"
}'
curl -XPUT 'http://localhost:9200/test/document/3'-d'{
"title" : "quiet brown"
}'

QUERY:
curl "localhost:9200/test/accounts/_search?pretty=true" -d '{
"query" : {
"text" : {
"message" : {
"query" : "quick",
"type" : "phrase_prefix"
}
}
}
}'
=> No hits