0

So,

I have been using the old multi_field type when creating template such as below.

"field_a": 
{
  "type": "multi_field",
  "fields": 
  {
   "searchable": {
     "index": "analyzed",
     "type": "string"
   },
   "field_a": {
    "index": "not_analyzed",
    "type": "string"
  }
 }
}

This works fine, when querying I can just do a terms aggregation on the "field_a" instead of having to remember to put the "field_a.raw" or something similar.

However, when I change this to the new syntax of just using the fields element this no longer works. When I do the terms aggregation using the below template the terms are split and not bringing the original value. So if the field had the value "testing a field" I would expect it to return "testing a field" as one term and not "testing", "a", "field" as individual terms. Note this is what is returned using the original template.

"field_a": 
{
  "type": "string",
  "fields": 
  {
   "searchable": {
    "index": "analyzed",
    "type": "string"
   },
   "field_a": {
    "index": "not_analyzed",
    "type": "string"
   }
  }
 }

I have tried moving the "index": "not_analyzed" into the initial field mapping, just under "type" however this gives me an error, "illegal field [index], only fields can be specified inside fields", when trying to index documents.

So my question is, is there a way I can make the initial field not_analyzed and then have an additional field which is searchable? Or do I have to change everything to include two separate field one with raw and one searchable seems a bit strange how this worked before mind you.

I am using

NEST: 1.7.2 ES: 1.5.2

Darren
  • 795
  • 1
  • 6
  • 10
  • You now need to aggregate on `field_a.field_a` and it should work. Also note that `field_a.searchable` is not useful anymore, you can use `field_a` directly. – Val May 20 '16 at 08:56
  • @Val - so there is no way to just have it know about field_a and this not_analyzed from the off? Yeah I was trying to ensure that it was the other way around, have one field as searchable and the original field as not_analyzed – Darren May 20 '16 at 08:59
  • In the new syntax, `field_a` refers to the top-level analyzed field. If you want that one to be `not_analyzed` you can definitely declare it as such and then you can aggregate on `field_a` only. Make sure to wipe your index and recreate it before running your aggregation again. – Val May 20 '16 at 09:02
  • how to do you declare the top level one as `not_analyzed` in the new syntax? I tried to add the `"index": "not_analyzed"` to the top level one but I got that error described when trying to index documents. Admittedly I am using version 1.5.2 and haven't testing on the latest version. – Darren May 20 '16 at 09:49
  • What version of NEST are you using and what version of Elasticsearch are you running against? – Russ Cam May 20 '16 at 10:33
  • @RussCam NEST: 1.7.2 Elasticsearch: 1.5.2 – Darren May 20 '16 at 10:57

0 Answers0