Marco Dinatsoli
Marco Dinatsoli

Reputation: 10570

elasticsearch put a raw field inside a field

Simply

this query

GET blabla/_search
{
  "_source": "city.raw"

}

gives zero results

but this one:

GET blabla/_search
    {
      "_source": "city"

    }

gives millions of documents.

the mapping for the field city is like this:

 "city": {
            "type": "string",
            "analyzer": "standard",
            "fields": {
              "raw": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },

as you see the .raw is there. what am i dong wrong please

Upvotes: 2

Views: 1561

Answers (1)

Val
Val

Reputation: 217314

The city.raw field is not stored in the _source it is just indexed so that you can search on it and perform aggregations on it.

What happens when you index a document such as

{ "city": "New York" }

is that

  • the city field will contain the two tokens new and york (i.e. analyzed)
  • whereas the city.raw field will contain the single token New York (i.e. not analyzed).

In your first example, you're trying to retrieve the city.raw field from the source, but no such field exists since it's a synthetic field created during the analysis process.

Upvotes: 3

Related Questions