What is the best way to make multy index search


(Nikolay Chankov) #1

Hi guys,

I guess, this is pretty trivial question, but so far I couldn't find the
answer.

The case: I have 4+ indices which contain different type of data (properly
mapped of this make sense). I need to execute a search across all indices
for a term, but when I search I need to put some weight over some of the
fields such as "name" should have higher weight than "address" or
"description".

Here is a concrete example:
Index: venues which has name (weight 4), address (weight 3) all other
fields (weight 2)
Index: users which has name (weight 4), address (weight 3) all other fields
(weight 2)
Index: event (which belongs to venue) which has name (weight 4), venue_name
(weight 3), address (weight 2) all other fields (weight 1)

So, I need to search for term or phrase like "John" which should search
within these indices and sort the results by the score. (there could be
user with First name "John", bar "Long John" or "event johns' bar event",
address containing John or even description which is in "all other fields".

To do so, I've read that I should use bool query together with multi match,
but there is also DIS max query and I don't know how to specify the index.
Here is what I am thinking to do so far:

curl -XGET 'http://localhost:9200/_search?pretty=true' -d '
{
"query" : {
"should" : [
{
"multi_match" : {
"query" : "John",
"fields" : ["name^4", "address^3"],
//somehow I need to specify that this is for index
venues
}
},
{
"multi_match" : {
"query" : "John",
"fields" : ["name^4", "address^3"],
//somehow I need to specify that this is for index users
}
},
{
"multi_match" : {
"query" : "John",
"fields" : ["name^4", "parent_name^3, "address^2"],
//somehow I need to specify that this is for index
events
}
}
]
}
}'

Again sorry for the trivial question.

Best regards and Merry Christmas!

Nik

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9a2645dd-def2-41f6-80a8-ecda1946e998%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Nikolay Chankov) #2

Actually, I've managed to achieve something with the following query:

curl -XGET 'http://localhost:9200/venues,users,events/_search?pretty=true'
-d '
{
"query" : {
"bool" : {
"should" : [
{
"indices" : {
"indices" : ["venues"],
"query" : {
"multi_match" : {
"query" : "Joh",
"fields" : ["name^4", "town^3"]
}
}
}
},
{
"indices" : {
"indices" : ["users"],
"query" : {
"multi_match" : {
"query" : "Joh",
"fields" : ["name^4", "town^3"]
}
}
}
},
{
"indices" : {
"indices" : ["events"],
"query" : {
"multi_match" : {
"query" : "Joh",
"fields" : ["name^4", "parent_name^3",
"town^2"]
}
}
}
}
]
}
}
}'

But still I struggled to find how to make the search by part of the phrase.
As you can see I've put Term, but this doesn't help me, since on a
specific phrase (like part of some user's name, which I know it exist) it
doesn't return the result with that user. i.e. if I search for "Chan",
since I have a user in the system, it should appear in the list, but it
doesn't If I complete the name "Chankov" I can see that record in the list.

Also is that the correct way of doing this type of query, or I need to try
another one?

Thank you!

On Monday, December 23, 2013 10:32:15 PM UTC, Nikolay Chankov wrote:

Hi guys,

I guess, this is pretty trivial question, but so far I couldn't find the
answer.

The case: I have 4+ indices which contain different type of data (properly
mapped of this make sense). I need to execute a search across all indices
for a term, but when I search I need to put some weight over some of the
fields such as "name" should have higher weight than "address" or
"description".

Here is a concrete example:
Index: venues which has name (weight 4), address (weight 3) all other
fields (weight 2)
Index: users which has name (weight 4), address (weight 3) all other
fields (weight 2)
Index: event (which belongs to venue) which has name (weight 4),
venue_name (weight 3), address (weight 2) all other fields (weight 1)

So, I need to search for term or phrase like "John" which should search
within these indices and sort the results by the score. (there could be
user with First name "John", bar "Long John" or "event johns' bar event",
address containing John or even description which is in "all other fields".

To do so, I've read that I should use bool query together with multi
match, but there is also DIS max query and I don't know how to specify the
index. Here is what I am thinking to do so far:

curl -XGET 'http://localhost:9200/_search?pretty=true' -d '
{
"query" : {
"should" : [
{
"multi_match" : {
"query" : "John",
"fields" : ["name^4", "address^3"],
//somehow I need to specify that this is for index
venues
}
},
{
"multi_match" : {
"query" : "John",
"fields" : ["name^4", "address^3"],
//somehow I need to specify that this is for index
users
}
},
{
"multi_match" : {
"query" : "John",
"fields" : ["name^4", "parent_name^3, "address^2"],
//somehow I need to specify that this is for index
events
}
}
]
}
}'

Again sorry for the trivial question.

Best regards and Merry Christmas!

Nik

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7e1ee34b-b8ee-44f1-a818-b825999b1e4e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #3