简体   繁体   中英

elastic search search index for keywords phrases or keywords

I'm new to Elastic Search and have an index with lots of articles in it. I have 3 main fields I use; title, snippet and date. I want to find the most common or top key-phrases or keywords for a specific date in the title field. I was hoping someone can provide an example on how to do this or at least point me in the right direction.

Many Thanks!

I think you are looking for terms aggregation . Try something like this

{
  "query": {
    "match": {
      "date": {
        "query": "your_date"
      }
    }
  },
  "size": 0,
  "aggs": {
    "common_words": {
      "terms": {
        "field": "title",
        "size": 10
      }
    }
  }
}

You will find common words at the top as they are ordered by count. If you are looking for phrases you might have to analyze your title field accordingly. You can map title with multiple analyzer . for eg standard analyzer for common words and shingle analyzer for common phrases.

You also might want to look into significant terms aggregation if you want to find something unusual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM