1

In my documents I have a field collaboration on which I would like to do aggregation queries. However I also want it to be full-text searchable, so I figured out I should make it a multifield. The field may look something like this:

...
"collaboration" : "CMS"
or
"collaboration" : ["ATLAS", "CMS"]
or
"collaboration" : "LHCb"
...

Following this advice: ElasticSearch term aggregation I changed the mapping to:

"collaboration": {
    "type": "string",
    "fields": {
        "raw": {
            "type": "string",
            "index": "not_analyzed"
        }
    }
},

And I run a query:

POST /my_index/_search
{
   "aggs": {
        "collaboration": {
            "terms": {
                "field": "collaboration.raw"
            }
        }
    }
}

And get nothing:

"hits": {
   "total": 5,
   "max_score": 1,
   "hits": [...]
},
"aggregations": {
   "collaboration": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": []
   }
}

Even when I try to use this field for searching it doesn't work:

POST /my_index/_search
{
    "query": {
        "query_string": {
            "query": "CMS",
            "fields": ["collaboration.raw"]
        }
    }
}

Should I change the mapping somehow because of the fact that the field is sometimes a list and sometimes a string? My research found that arrays are supposed to be supported out of the box. Any suggestions what might be wrong here?

Community
  • 1
  • 1
stpk
  • 2,015
  • 1
  • 16
  • 23

1 Answers1

0

Solved it thanks to Andrei Stefan!

All the documents needed to be reindexed after changing the mapping, small yet painful detail.

Community
  • 1
  • 1
stpk
  • 2,015
  • 1
  • 16
  • 23