Elastic search6.2.2 Implementation of search records query, similar to Sina Weibo, the same search record in the back of the time will cover the previous (main idea: keywords to heavy, and then sorted by time)
Create an index first
// My search PUT my_search{ "Settings": { "Number_of_replicas": 0 }, "mappings" : {"_doc" :{" Properties": {"user": {"type": "Integer"}, "word": {"type": "Keyword"}, "datetime": { "type": "Date", " Format ":" Yyyy-mm-dd hh:mm:ss| | yyyy-mm-dd| | Epoch_millis " } }}}}
Insert Search Record
POST My_search/_doc//auto-Generate ID{ "User": 1, "word": "Blockchain", "datetime": "2018-02-08 23:58:59"}{ "User": 1, "word": "Liu Ping", "datetime": "2018-03-08 23:58:59"}{ "User": 1, "word": "Hello", "datetime": "2018-04-08 23:58:59"}{ "User": 1, "word": "I'm Good", "datetime": "2018-05-08 23:59:59"}{ "User": 1, "word": "Hello", "datetime": "2018-06-08 23:58:59"}{ "User": 1, "word": "He's good", "datetime": "2018-07-09 23:58:59"}{ "User": 1, "word": "He's good", "datetime": "2018-08-09 23:58:59"}
Search record Visual interface (to sort by time) after writing to the document
We're going to read it down here.
POST My_search/_search//My recent search record (show 10 article){ "Query":{ "Match":{ "User": "1" } }, "Aggs":{ "My_so":{ "Terms":{ "Field": "Word", "Size": 10, "Order":{ "Max_time": "desc" } }, "Aggs":{ "Max_time":{ "Max":{ "Field": "DateTime" } } } } }, "Size": 0, "From": 0}
Search results:
Elastic search6.2.2 Implement User Search record query (de-weight, sort)