简体   繁体   中英

Nested documents in Elastic Search

we have a program that will use ElasticSearch. We have the need to query using joins, which is not supported in elasticsearch, so we are left with either nested or parent-child relationships. I have read that using parent-child can cause significant performance issues , so we are thinking of going with nested documents.

We index/query on products but we also have customers and vendors. So, this is my thinking for my product mapping:

{
    "mappings" : {
      "products" : {
        "dynamic": false,
        "properties" : {
          "availability" : {
            "type" : "text"
          },
          "customer": {
              "type": "nested"
          },
          "vendor": {
              "type": "nested"
          },
          "color" : {
                "type" : "text"
            }
          },
          "created_date" : {
            "type" : "text"
          }
        }
      }
    }
}

Here customer and vendor are my mapped fields.

Does this mapping look correct? Since I am setting dynamic to false, do I need to specify the contents of the customer and vendor sub documents? If so, how would I do that?

My team found parent/child relationships to be incredibly detrimental to our performance, so I think you're probably making a good decision to use nested fields.

If you use dynamic: false then undefined fields will not be added to the mapping. You can either set it to true and those fields should be added as you index or you can define the properties on the nested documents yourself:

{
"mappings" : {
  "products" : {
    "dynamic": false,
    "properties" : {
      ...
      "customer": {
          "type": "nested",
          "properties": {
              "prop a": {...},
              "prop b": {...}
          }
      },
      "vendor": {
          "type": "nested",
          "properties": {
              "prop a": {...},
              "prop b": {...}
          }
      },
      ...
    }
  }
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM