I have 2 types Author and Book. I want to search both types and return matches from the fields Author.name and Book.title. How would I complete this query?
GET /bookstore/author,book/_search ...
You can make a query to the index, not only the type: /yourindex/_search.
Now, you should use a multi match query to control your results better:
{
"multi_match" : {
"query": "Will Smith", "fields": [
"type1.title", "type2.name"
]
}
}
More info: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
There are a few approaches based on what you're trying to accomplish.
It is possible to search both given that book doesn't have an attribute "name", and author doesn't have an attribute "title". If you search for a field that doesn't exist elasticsearch will still try given that the data in the model is schema-less, and a mapping simply defines how to index fields but doesn't necessarily define the structure of the documents.
If you're trying to make a single search for both book and author then I'd recommend doing 2 separate queries, as you'll get 2 separate types of documents which may need to be treated accordingly.