I'm using this query to search a field for occurrences of phrases.
"query": {
"match_phrase": {
"content": "my test phrase"
}
}
I need to calculate how many matches occurred for each phrase per document (if this is even possible?)
I've considered aggregators but think these don't meet the requirements as these will give me the number of matches over the whole index not per document. `enter code here
I don't think there's a straightforward way to get those phrase counts from Elasticsearch.
If it's just the occasional query for which you would want to know this, you could add "explain": true to your search request (on the same level as your "query"). The response will contain a phraseFreq, which is the phrase frequency, i.e. the number of times the phrase occurs in the content field of this document.
Keep in mind though that adding "explain" to your search request will slow down your queries significantly, so it's definitely not something you want to do for all search requests. But for the occasional request, it's perfectly fine.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.