Retrieving Copy_to/Stored fields

I noticed that copy_to fields work for aggregations but don't get show up in a Match all query or any similar query. Upon further searching I figured setting "store": true in the Field mappings should help but I still was not able to see them in searches.

This was the syntax I was trying to use:

GET index/_search
    {
      "stored_fields": [
        "CopyField"
      ],
      "query": {
        "match_all": {}
      }
    }

Am I missing something here?

Welcome!

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

I had created a copy_to field as of an existing field by altering its mapping below:
{
  "properties": {
    "ExistingField": {
      "type": "date",
      "copy_to": "CopiedField"
    },
    "CopiedField": {
      "type": "date",
      "store": true
    }
  }
}

I had used "store": "true" since I wanted this new fields value to be retrieved when I do a search. Aggregations with the "CopiedField" work fine but when I try to search for a value in this new CopiedField I cannot see anything being retrieved:

{
  "stored_fields": [
      "CopiedField"
     ],
  "query": {
  "match_all": {}
  }
}

How do I retrieve the value of this "CopiedField" in a simple search?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

Sorry it took time to answer.

I tried your example. Here a full script:

PUT index
{
  "mappings": {
    "properties": {
      "ExistingField": {
        "type": "date",
        "copy_to": "CopiedField"
      },
      "CopiedField": {
        "type": "date",
        "store": true
      }
    }
  }
}

PUT index/_doc/1
{
  "ExistingField": "2019-11-25"
}
GET index/_search
{
  "stored_fields": [
    "CopiedField"]
}

This gives:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "fields" : {
          "CopiedField" : [
            "2019-11-25T00:00:00.000Z"
          ]
        }
      }
    ]
  }
}

So everything looks fine on my side. I tested with 7.4.2.