Till now, we
did structured search on documents, it is time to perform full text search.
Get all employees whose hobby is “Reading books”.
GET /xyz/employees/_search { "query": { "match": { "hobbies": "Reading books" } } }
You will get
following result.
{ "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 2, "max_score": 0.2169777, "hits": [ { "_index": "xyz", "_type": "employees", "_id": "2", "_score": 0.2169777, "_source": { "firstName": "Sankalp", "lastName": "Dubey", "hobbies": [ "Shopping", "Swimming", "Reading books" ], "age": 32 } }, { "_index": "xyz", "_type": "employees", "_id": "1", "_score": 0.13561106, "_source": { "firstName": "Phalgun", "lastName": "Garimella", "hobbies": [ "Watching movies", "Stamp collection", "Reading books", "Playing Cricket" ], "age": 30 } } ] } }
Observe the
field “_score” in the result.
For
document 2,
"_score" value is 0.2169777
document 1 :
"_score" value is 0.13561106
“_score”
value specifies how well each document matches the query. If “_score” value is
high, the document matches more, else less.
No comments:
Post a Comment