Elastic Search - Display all different array values

For a field rendered as a string, I have stored a list of strings in an ES index, for example:

  subject: ["Scientific Research", "Numerical Analysis", "History of Art"]

      

I would like to query this field and get the full category names with their frequency. What I've tried so far with facets:

  "query":{
       "match_all": {}
   }, 
   "facets":{
       "tag":{
           "terms":{
               "field":"subject"}
             }
   }  

      

doesn't work as expected because it splits my subject fields into tokens and returns me the most popular frequent passwords. How can I get the complete records sorted by counts for the parsed field, and if possible not just the top 10? Thank!

+1


source to share


1 answer


I would use multi-field

to define your mapping like so:

{
   .....
        ....
            .....
            "subject": {
                "type": "multi_field",
                "store": "yes",
                "fields": {
                    "analyzed": {
                        "type": "string",
                        "analyzer": "standard"
                    },
                    "notanalyzed": {
                        "type": "string",
                        "index": "not_analyzed"
                    }
                }
            }

      



Then I would perform your field cut notanalyzed

like this:

"query":{
      "match_all": {}
  }, 
  "facets":{
      "tag":{
          "terms":{
              "field":"subject.notanalyzed",
              "size": 50
            }
        }
  }  

      

+1


source







All Articles