1

As I understand, when creating an index, you can define the fields that the documents will have in that index by defining a mapping

PUT person
{
  "mappings": {
    "properties": {
      "firstName":{"type":"text"},
      "secondName":{"type":"text"},
      "age":{"type":"integer"}
    }
  }
}

But I also find a that queries are sometimes written like this, with a _doc inside the mapping

PUT person
{
  "mappings": {
    "_doc":{
      "properties": {
        "firstName":{"type":"text"},
        "secondName":{"type":"text"},
        "age":{"type":"integer"}
      }
    }
  }
}

What does putting _doc do?

  • Does this answer your question? [what does \_doc represents in elasticsearch?](https://stackoverflow.com/questions/35747862/what-does-doc-represents-in-elasticsearch) – zsltg Mar 28 '20 at 23:43
  • ^ The above comment is a duplicate of this question. For which elasticsearch version you're talking about? – Harshit Mar 29 '20 at 07:17

1 Answers1

0

_doc in the second mapping is loosely related to how mappings used to be defined before 7.0.

Instead of _doc it'd include the type of your document. With that being said, the 2nd mapping would work prior to 7.0 w/o a problem, and >=7.0 if you specified include_type_name, i.e. PUT person?include_type_name=true.

More info here: https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0

The idea of all of this is that one index should only include one type of document, thereby rendering the type first redundant and later deprecated.

Joe - GMapsBook.com
  • 15,787
  • 4
  • 23
  • 68