0

With the planned removal of mapping types coming to ElasticSearch, does this also mean the deprecation of nested documents and nested queries? How would/will ElasticSearch support queries of nested objects in typeless context?

The functionality I'm considering is being able to return only the hits in a nested array that match search criteria.

Edit 1: Example mapping + query in ElasticSearch version 6

ElasticSearch 6 Mapping

{
    "rec": {
        "mappings": {
            "history": {
                "properties": {
                    "dateCompleted": {
                        "type": "keyword"
                    },
                    "dateCreated": {
                        "type": "keyword"
                    },
                    "dateOrdered": {
                        "type": "keyword"
                    },
                    "dateToArrive": {
                        "type": "keyword"
                    },
                    "details": {
                        "type": "nested",
                        "properties": {

                            "clientId": {
                                "type": "keyword"
                            },
                            "company": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            },
                            "orderNumber": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

ElasticSearch 6 Query

{
  "from": 0,
  "query": {
    "nested": {
      "inner_hits": {},
      "path": "details",
      "query": {
        "bool": {
          "must": [
            {
              "match_phrase": {
                "details.company.keyword": {
                  "query": "ABCD"
                }
              }
            }
          ]
        }
      }
    }
  },
  "size": 10,
  "sort": [],
  "_source": false
}
Matt Vaughan
  • 1,135
  • 2
  • 13
  • 19
  • I don't think it would have impact on this, I would like to try that, for that it would be great if you can share ur mapping, sample docs and query, btw +1 for good question –  Feb 18 '20 at 06:48
  • Thanks, @es-enthu. I added a stripped-down example mapping and query to hopefully demonstrate how it is working in ElasticSearch 6. – Matt Vaughan Feb 18 '20 at 07:03

2 Answers2

2

No, the removal of _type has no impact on nested documents and queries.

In the past, people used different types in one index for modeling serveral entities. The problem was, that some of the entities had the same field but different field type. For example "version", in one entity an string but integer in other. This caused a problem, because there is no solution for this scenario.

EDIT: Nested objects is an mapping dataype for modeling complex properties within a document like this:

{
  "_id" : "12345",
  "user" : { "login":"foo", "email":"foo@example.com"}
}

Please note the user object within the document itself or the "details" property in your mapping above. More examples are available here: https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html

The document doctype is a set of properies defining a documents structure by its mapping.

In the past, there was the possibility of modelling a "car" and a "plane" in one index using two doctypes. In current versions there is just one doctype, mainly named _doc and it will be completely removed in future versions.

In the documentation you've linked (removal of types) there is a good example of multi doctype twitter index defining a user and tweet doctype in one index.

ibexit
  • 3,465
  • 1
  • 11
  • 25
  • So is the PUT API not being removed at `/_mapping`? How would you specify that a field is nested? How would you query to determine if a field was nested? The NEST wrapper library has removed the `GetMapping` call. https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-breaking-changes.html – Matt Vaughan Feb 18 '20 at 07:31
0

It looks like the GetMapping method on the NEST client in versions 7+ has moved to IElasticSearchClient.Indicies.GetFieldMapping. My misunderstanding was that all types were being removed. In reality, it seems like the plan is to just have one type per index. Thanks @ibexit for the clarification.

Matt Vaughan
  • 1,135
  • 2
  • 13
  • 19