Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch Popular Keywords

Does elasticsearch provide a way to keep track of popular keywords? For example, at a given time period, I would like to know the keywords that appear the mostly frequently in queries.

If elasticsearch does not have such a feature, what would be a good way to implement it using elasticsearch?

Thanks!

like image 606
flamecto Avatar asked Apr 18 '13 22:04

flamecto


People also ask

What are keywords in Elasticsearch?

The keyword family includes the following field types: keyword , which is used for structured content such as IDs, email addresses, hostnames, status codes, zip codes, or tags. constant_keyword for keyword fields that always contain the same value. wildcard for unstructured machine-generated content.

What is Elasticsearch known for?

Elasticsearch allows you to store, search, and analyze huge volumes of data quickly and in near real-time and give back answers in milliseconds. It's able to achieve fast search responses because instead of searching the text directly, it searches an index.

What is keyword in Opensearch?

A keyword field type contains a string that is not analyzed. It allows only exact, case-sensitive matches.

Is Elasticsearch good for analytics?

Elasticsearch is a highly scalable open-source full-text search and analytics engine. It allows you to store, search, and analyze big volumes of data quickly and in near real time. It is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.


2 Answers

I don't think there is a build-in way for that, but it should be quite easy to achieve via a terms facet

What you'd have to do is:

  1. Save all query keywords along with a timestamp in an elasticsearch index
  2. Run a match_all query filtered by the time interval you are interested in and apply a term facet onto it

Unfortunately I don't have the time to write you an example, but that should lead you to the solution.

Here is an example:

// Demo index
curl -XDELETE 'http://localhost:9200/queries/'
curl -XPUT 'http://localhost:9200/queries/'

// Add some data
curl -XPUT 'http://localhost:9200/queries/query/1' -d '
{ 
    "date": "2013-02-19T12:57:23", 
    "query": "Trying out ElasticSearch, so far so good?"
}'

curl -XPUT 'http://localhost:9200/queries/query/2' -d '
{ 
    "date": "2013-03-02T11:27:23", 
    "query": "Lets give ElasticSearch another try"
}'

curl -XPUT 'http://localhost:9200/queries/query/3' -d '
{ 
    "date": "2013-04-02T08:27:23", 
    "query": "OK, why dont we stick to SOLR?"
}'

curl -XPUT 'http://localhost:9200/queries/query/4' -d '
{ 
    "date": "2013-04-19T11:27:23", 
    "query": "Couse ElasticSearch is so much cooler, its bonsai cool"
}'

// Query it
curl -XGET 'http://localhost:9200/queries/query/_search?pretty=true' -d '
{
    "query" : {
        "filtered" : {
            "filter" : {
                "range" : {
                    "date" : {
                        "gte" : "2013-01-01T00:00:00",
                        "lt" : "2013-04-01T00:00:00"
                    }
                }
            },
            "query" : {
                "match_all" : {}
            }
        }
    },
    "facets": {
        "keywords": {
            "terms": {
                "field": "query"
            }
        }
    }
}
'

Adjust the date range in the query to see the changes of the output

like image 167
Thorsten Avatar answered Oct 17 '22 22:10

Thorsten


The Approved answer not working anymore because Facets have been removed and replaced with terms aggregation instead.

like image 20
Abdellah Chadidi Avatar answered Oct 17 '22 20:10

Abdellah Chadidi