Using custom analyzer and nGram to do partial search on a property


(Aditya Herlambang) #1

I am trying to get partial search on a property of my entity working by
using the nGram and edgeNGram working, however
I am always getting 0 results all the time. Why is this? Here's my full
code, mappings, and sample datahttps://gist.github.com/aherlambang/027dd7316a999cb9a1ffthat I am trying to search on.

Essentially I wanted to search for 'moonl' and it should match the
username, because the username is moonlyshop and should return the Shop,
however I am getting 0 results. What am I doing wrong?

--
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.


(David Pilato) #2

I guess it's because you search in _all field (default when you use q=moonl).
You should try q=shop_name:moonl or use a MatchQuery with the query DSL.

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 03:01, Aditya Herlambang aditya15417@gmail.com a écrit :

I am trying to get partial search on a property of my entity working by using the nGram and edgeNGram working, however
I am always getting 0 results all the time. Why is this? Here's my full code, mappings, and sample data that I am trying to search on.

Essentially I wanted to search for 'moonl' and it should match the username, because the username is moonlyshop and should return the Shop,
however I am getting 0 results. What am I doing wrong?

--
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.

--
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.


(Aditya Herlambang) #3

but doing q=shop_name:moonl means that i will only be searching on the store name and not the shops picture caption, is there a way to make multiple search at one? so doing q=moonl and q=shop_name:moonl at the same time?

--
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.


(David Pilato) #4

You can search for q=moonl q=shop_name:moonl
Or +q=moonl and +q=shop_name:moonl

But I really recommend using QueryDsl http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 16:11, Aditya Herlambang aditya15417@gmail.com a écrit :

but doing q=shop_name:moonl means that i will only be searching on the store name and not the shops picture caption, is there a way to make multiple search at one? so doing q=moonl and q=shop_name:moonl at the same time?

--
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.

--
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.


(David Pilato) #5

Sorry I meant: +q=moonl +q=shop_name:moonl is equivalent to q=moonl and q=shop_name:moonl.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 19:31, David Pilato david@pilato.fr a écrit :

You can search for q=moonl q=shop_name:moonl
Or +q=moonl and +q=shop_name:moonl

But I really recommend using QueryDsl http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 16:11, Aditya Herlambang aditya15417@gmail.com a écrit :

but doing q=shop_name:moonl means that i will only be searching on the store name and not the shops picture caption, is there a way to make multiple search at one? so doing q=moonl and q=shop_name:moonl at the same time?

--
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.

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.

--
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.


(Aditya Herlambang) #6

So I tried using multi match query by specifying the following:

{
"multi_match" : {
"query" : "some query",
"fields" : [ "username", "fullname", "caption" ]
}
}

however it seems now the search is not searching the caption (while in fact
caption is the single most important one). Why is this? I believe this is
because the caption is a nested property inside the shop.
So how do I specify the nested property to be searched in a multi match?

On Sunday, November 10, 2013 2:21:08 AM UTC+7, David Pilato wrote:

Sorry I meant: +q=moonl +q=shop_name:moonl is equivalent to q=moonl and
q=shop_name:moonl.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 19:31, David Pilato <da...@pilato.fr <javascript:>> a
écrit :

You can search for q=moonl q=shop_name:moonl
Or +q=moonl and +q=shop_name:moonl

But I really recommend using QueryDsl
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 16:11, Aditya Herlambang <adity...@gmail.com<javascript:>>
a écrit :

but doing q=shop_name:moonl means that i will only be searching on the
store name and not the shops picture caption, is there a way to make
multiple search at one? so doing q=moonl and q=shop_name:moonl at the same
time?

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.


(Aditya Herlambang) #7

I also think in this case I'd have to use the nested query?

On Monday, November 11, 2013 11:36:54 AM UTC+7, Aditya Herlambang wrote:

So I tried using multi match query by specifying the following:

{
"multi_match" : {
"query" : "some query",
"fields" : [ "username", "fullname", "caption" ]
}
}

however it seems now the search is not searching the caption (while in
fact caption is the single most important one). Why is this? I believe this
is because the caption is a nested property inside the shop.
So how do I specify the nested property to be searched in a multi match?

On Sunday, November 10, 2013 2:21:08 AM UTC+7, David Pilato wrote:

Sorry I meant: +q=moonl +q=shop_name:moonl is equivalent to q=moonl and
q=shop_name:moonl.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 19:31, David Pilato da...@pilato.fr a écrit :

You can search for q=moonl q=shop_name:moonl
Or +q=moonl and +q=shop_name:moonl

But I really recommend using QueryDsl
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 16:11, Aditya Herlambang adity...@gmail.com a écrit :

but doing q=shop_name:moonl means that i will only be searching on the
store name and not the shops picture caption, is there a way to make
multiple search at one? so doing q=moonl and q=shop_name:moonl at the same
time?

--
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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.


(David Pilato) #8

Why do you define a nested document?

As far as I can see, you probably don't need it here.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 11 nov. 2013 à 05:40, Aditya Herlambang aditya15417@gmail.com a écrit :

I also think in this case I'd have to use the nested query?

On Monday, November 11, 2013 11:36:54 AM UTC+7, Aditya Herlambang wrote:
So I tried using multi match query by specifying the following:

{
"multi_match" : {
"query" : "some query",
"fields" : [ "username", "fullname", "caption" ]
}
}
however it seems now the search is not searching the caption (while in fact caption is the single most important one). Why is this? I believe this is because the caption is a nested property inside the shop.
So how do I specify the nested property to be searched in a multi match?

On Sunday, November 10, 2013 2:21:08 AM UTC+7, David Pilato wrote:
Sorry I meant: +q=moonl +q=shop_name:moonl is equivalent to q=moonl and q=shop_name:moonl.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 19:31, David Pilato da...@pilato.fr a écrit :

You can search for q=moonl q=shop_name:moonl
Or +q=moonl and +q=shop_name:moonl

But I really recommend using QueryDsl http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 16:11, Aditya Herlambang adity...@gmail.com a écrit :

but doing q=shop_name:moonl means that i will only be searching on the store name and not the shops picture caption, is there a way to make multiple search at one? so doing q=moonl and q=shop_name:moonl at the same time?

--
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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.

--
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.


(Aditya Herlambang) #9

Let me explain my scenario.

I have a Shop, the shop has a username and also a full name.
The Shop has a nested property which is shopPictures, and each shopPictures
has a caption associated with it. So this shopPictures is nested.

I wanted to do a search on the caption's first and then the username and
full name as the priority. When I do the multi query it doesn't search the
caption of the shopPictures.
How do I do so?

On Monday, November 11, 2013 12:52:16 PM UTC+7, David Pilato wrote:

Why do you define a nested document?

As far as I can see, you probably don't need it here.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 11 nov. 2013 à 05:40, Aditya Herlambang <adity...@gmail.com<javascript:>>
a écrit :

I also think in this case I'd have to use the nested query?

On Monday, November 11, 2013 11:36:54 AM UTC+7, Aditya Herlambang wrote:

So I tried using multi match query by specifying the following:

{
"multi_match" : {
"query" : "some query",
"fields" : [ "username", "fullname", "caption" ]
}
}

however it seems now the search is not searching the caption (while in
fact caption is the single most important one). Why is this? I believe this
is because the caption is a nested property inside the shop.
So how do I specify the nested property to be searched in a multi match?

On Sunday, November 10, 2013 2:21:08 AM UTC+7, David Pilato wrote:

Sorry I meant: +q=moonl +q=shop_name:moonl is equivalent to q=moonl and
q=shop_name:moonl.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 19:31, David Pilato da...@pilato.fr a écrit :

You can search for q=moonl q=shop_name:moonl
Or +q=moonl and +q=shop_name:moonl

But I really recommend using QueryDsl
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 16:11, Aditya Herlambang adity...@gmail.com a écrit :

but doing q=shop_name:moonl means that i will only be searching on the
store name and not the shops picture caption, is there a way to make
multiple search at one? so doing q=moonl and q=shop_name:moonl at the same
time?

--
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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.


(David Pilato) #10

Ok. Try BoolQuery with should clauses.
For the nested field, use the NestedQuery with a MatchQuery.
For the other fields, use the MultiMatch Query

Does it help?

David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 11 nov. 2013 à 08:01, Aditya Herlambang aditya15417@gmail.com a écrit :

Let me explain my scenario.

I have a Shop, the shop has a username and also a full name.
The Shop has a nested property which is shopPictures, and each shopPictures has a caption associated with it. So this shopPictures is nested.

I wanted to do a search on the caption's first and then the username and full name as the priority. When I do the multi query it doesn't search the caption of the shopPictures.
How do I do so?

On Monday, November 11, 2013 12:52:16 PM UTC+7, David Pilato wrote:
Why do you define a nested document?

As far as I can see, you probably don't need it here.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 11 nov. 2013 à 05:40, Aditya Herlambang adity...@gmail.com a écrit :

I also think in this case I'd have to use the nested query?

On Monday, November 11, 2013 11:36:54 AM UTC+7, Aditya Herlambang wrote:
So I tried using multi match query by specifying the following:

{
"multi_match" : {
"query" : "some query",
"fields" : [ "username", "fullname", "caption" ]
}
}
however it seems now the search is not searching the caption (while in fact caption is the single most important one). Why is this? I believe this is because the caption is a nested property inside the shop.
So how do I specify the nested property to be searched in a multi match?

On Sunday, November 10, 2013 2:21:08 AM UTC+7, David Pilato wrote:
Sorry I meant: +q=moonl +q=shop_name:moonl is equivalent to q=moonl and q=shop_name:moonl.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 19:31, David Pilato da...@pilato.fr a écrit :

You can search for q=moonl q=shop_name:moonl
Or +q=moonl and +q=shop_name:moonl

But I really recommend using QueryDsl http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 nov. 2013 à 16:11, Aditya Herlambang adity...@gmail.com a écrit :

but doing q=shop_name:moonl means that i will only be searching on the store name and not the shops picture caption, is there a way to make multiple search at one? so doing q=moonl and q=shop_name:moonl at the same time?

--
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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.

--
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.


(system) #11