code: Document createDocument(Entity entity) {
      int maxIndexingDepth = entity.getEntityType().getIndexingDepth();
      XContentBuilder contentBuilder;
      try {
        contentBuilder = XContentFactory.contentBuilder(JSON);
        XContentGenerator generator = contentBuilder.generator();
        generator.writeStartObject();
        createRec(entity, generator, 0, maxIndexingDepth);
        generator.writeEndObject();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      String documentId = toElasticsearchId(entity.getIdValue());
      return Document.create(documentId, contentBuilder);
    }
docs: Create Elasticsearch document source content from entity
  
  @param entity the entity to convert to document source content
  @return Elasticsearch document source content