More like this
The ElasticSearch functionality is not only about searching documents based on selected criteria. For example, we can use it in our application to find similar products to the ones that were returned by a user query.
In fact, we already know something about this functionality from Chapter 2, Searching Your Data, where we saw the "more like this" query. But, in the mentioned query, we have to construct the like_text
field. ElasticSearch can generate this data based on the example document and provides a special endpoint for this.
Example data
For our example, let's imagine we have a travel agency where every available location is assigned a set of tags describing it. The simplified version of the data can look like this:
{ "index": { "_index" : "travel", "_type" : "loc", "_id" : 1}} { "name" : "beautiful hotel by the sea", "tags" : ["sea", "greece", "beach"] } { "index": { "_index" : "travel", "_type" : "loc", "_id" : 2}} { "name" : "a small cottage in the mountains", "tags" :...