# What is the best way to make multy index search

**URL:** <https://discuss.elastic.co/t/what-is-the-best-way-to-make-multy-index-search/15006>\
**Category:** Elasticsearch\
**Created:** [December 23, 2013, 10:32pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-make-multy-index-search/15006 "2013-12-23T22:32:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikolay\_Chankov](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikolay\_Chankov](https://discuss.elastic.co/u/Nikolay_Chankov)\
**Post date:** [December 23, 2013, 10:32pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-make-multy-index-search/15006/1 "2013-12-23T22:32:15Z")

</div>

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](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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Nikolay\_Chankov](https://avatars.discourse-cdn.com/v4/letter/n/a8b319/32.png) [@Nikolay\_Chankov](https://discuss.elastic.co/u/Nikolay_Chankov)\
**Post date:** [December 23, 2013, 11:00pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-make-multy-index-search/15006/2 "2013-12-23T23:00:02Z")

</div>

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

curl -XGET '[http://localhost:9200/venues,users,events/\_search?pretty=true](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](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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:59am UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-make-multy-index-search/15006/3 "2017-07-06T01:59:33Z")

</div>


