class_docstr: Represents an elasticsearch based tf.data.Dataset
  
  The records fetched from the cluster are structured in their content and
  require additional processing to make them ready for training the
  machine learning model.
  
  There are various ways of converting column data into features and using them
  to train the models. For example, let's consider an elasticsearch dataset
  which contains records having the `fare`, `age` and `survived` keys. The
  values of the `survived` key act as our label data.
  
  >>> import tensorflow as tf
  >>> from tensorflow import feature_column
  >>> from tensorflow.keras import layers
  >>> import tensorflow_io as tfio
  
  >>> dataset = tfio.experimental.elasticsearch.ElasticsearchIODataset(
                  nodes=["localhost:9092"],
                  index="people",
                  doc_type="survivors")
  >>> dataset = dataset.map(lambda v: (v, v.pop("survived")))
  >>> dataset = dataset.batch(10)
  
  >>> fare = feature_column.numeric_column('fare') # numeric column
  >>> age = feature_column.numeric_column('age')
  >>> age_buckets = feature_column.bucketized_column(age) # bucketized column
  
  >>> feature_columns = [cost, age_buckets]
  >>> feature_layer = tf.keras.layers.DenseFeatures(feature_columns)
  
  The `feature_layer` can now be added as the input layer to the `tf.keras` model.
  
  >>> model = tf.keras.Sequential([
          feature_layer,
          layers.Dense(128, activation="relu"),
          layers.Dropout(0.1),
          layers.Dense(1),
      ])
  >>> model.compile(optimizer="adam",
      loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
      metrics=["accuracy"],
  )
  >>> model.fit(dataset, epochs=5)
  
  Additionally, while creating the `ElasticsearchIODataset`, headers can be passed
  to connect to clusters that require additional configuration. For example, passing
  the authorization headers:
  
  >>> HEADERS = {"Authorization": "Basic ZWxhc3RpYzpkZWZhdWx0X3Bhc3N3b3Jk"}
  >>> dataset = tfio.experimental.elasticsearch.ElasticsearchIODataset(
                  nodes=["localhost:9092"],
                  index="people",
                  doc_type="survivors",
                  headers=HEADERS)
docstr: Prepare the ElasticsearchIODataset.
  
  Args:
      nodes: A `tf.string` tensor containing the hostnames of nodes
          in [protocol://hostname:port] format.
          For example: ["http://localhost:9200"]
      index: A `tf.string` representing the elasticsearch index to query.
      doc_type: (Optional) A `tf.string` representing the type of documents
          in the index to query.
      headers: (Optional) A dict of headers. For example:
          {'Content-Type': 'application/json'}
docstr_tok: ["Prepare","the","ElasticsearchIODataset",".","Args",":","nodes",":","A","`","tf.string","`","tensor","containing","the","hostnames","of","nodes","in","[","protocol",":","\/\/hostname",":","port","]","format",".","For","example",":","[","``","http",":","\/\/localhost:9200","''","]","index",":","A","`","tf.string","`","representing","the","elasticsearch","index","to","query",".","doc_type",":","(","Optional",")","A","`","tf.string","`","representing","the","type","of","documents","in","the","index","to","query",".","headers",":","(","Optional",")","A","dict","of","headers",".","For","example",":","{","'Content-Type","'",":","'application\/json","'","}"]
code: def __init__(
      self, nodes, index, doc_type=None, headers=None, internal=True
  ):
      """Prepare the ElasticsearchIODataset.
  
      Args:
          nodes: A `tf.string` tensor containing the hostnames of nodes
              in [protocol://hostname:port] format.
              For example: ["http://localhost:9200"]
          index: A `tf.string` representing the elasticsearch index to query.
          doc_type: (Optional) A `tf.string` representing the type of documents
              in the index to query.
          headers: (Optional) A dict of headers. For example:
              {'Content-Type': 'application/json'}
      """
      with tf.name_scope("ElasticsearchIODataset"):
          assert internal
  
          handler = _ElasticsearchHandler(
              nodes=nodes,
              index=index,
              doc_type=doc_type,
              headers_dict=headers,
          )
          (
              resource,
              columns,
              dtypes,
              request_url,
          ) = handler.get_healthy_resource()
  
          dataset = tf.data.experimental.Counter()
          dataset = dataset.map(
              lambda i: handler.get_next_batch(
                  resource=resource, request_url=request_url
              )
          )
          dataset = dataset.apply(
              tf.data.experimental.take_while(
                  lambda v: tf.greater(tf.shape(v)[0], 0)
              )
          )
          dataset = dataset.flat_map(
              lambda x: tf.data.Dataset.from_tensor_slices(x)
          )
          dataset = dataset.map(
              lambda v: handler.parse_json(
                  v, columns=columns, dtypes=dtypes
              ),
              num_parallel_calls=tf.data.experimental.AUTOTUNE,
          )
          self._dataset = dataset
  
          super().__init__(self._dataset._variant_tensor)
  
file_path: io/tensorflow_io/python/experimental/elasticsearch_dataset_ops.py
imports: from urllib.parse import urlparse
  import tensorflow
  from tensorflow_io.python.ops import core_ops
  from tensorflow_io.python.experimental import serialization_ops
label_desc: Use image node_id 1 to create a new ElasticsearchIODataset object from inherited base classes: tf.compat.v2.data with example: obj = ElasticsearchIODataset(nodes, index, doc_type, headers, internal)