Index a new document

@param array $data the document data
@param string $index
@param string $type
@param string|number $id
@param array $parameters
@return array
480539
protected function __create(array $data, $index, $type, $id = null, array $parameters = []) {
        $parameters+=["api" => "create"];
        $api = strtolower($parameters["api"]) == "index" ? "index" : "create";
        unset($parameters["api"]);
        $result = $this->client->$api([
            'index' => $index,
            'type' => $type,
            'body' => $data] + ($id ? ['id' => $id] : []) + $parameters);
        if (array_key_exists('_shards', $result) && array_key_exists('failed', $result['_shards']) && $result['_shards']['failed'] > 0) {
            throw new Exception('Failed to create the document. Serialized results: ' + json_encode($result));
        } else {
            $result = $this->__find($result['_index'], $result['_type'], $result['_id']);
        }
        return $result;
    }
1220729
public function update($index, $type, $id, $document)
    {
        $request = $this->createRequestInstance(self::UPDATE_DOCUMENT, $index, $type);
        $request->setId($id);
        $request->setBody($document);

        return $this->client->send($request);
    }
240324
public function get($index, $type, $id)
    {
        $request = $this->createRequestInstance(self::GET_DOCUMENT, $index, $type);
        $request->setId($id);

        return $this->client->send($request);
    }
742917
public function update($id, $data)
    {
        $document = $this->client->put(
            sprintf('buckets/%d/documents/%d.json', $this->bucket, $id),
            [
                'json' => $data,
            ]
        );

        return new Document($this->response($document));
    }
1243103
public function delete($index, $type, $id)
    {
        $request = $this->createRequestInstance(self::DELETE_DOCUMENT, $index, $type);
        $request->setId($id);

        return $this->client->send($request);
    }
942746
private function createDataTableMapFromIndex($index, $resultIndices, $keyMetadata)
    {
        $result = new DataTable\Map();
        $result->setKeyName(reset($resultIndices));
        $resultIndex = key($resultIndices);

        array_shift($resultIndices);

        $hasIndices = !empty($resultIndices);

        foreach ($index as $label => $value) {
            $keyMetadata[$resultIndex] = $this->createTableIndexMetadata($resultIndex, $label);

            if ($hasIndices) {
                $newTable = $this->createDataTableMapFromIndex($value, $resultIndices, $keyMetadata);
            } else {
                $newTable = $this->createDataTable($value, $keyMetadata);
            }

            $result->addTable($newTable, $this->prettifyIndexLabel($resultIndex, $label));
        }

        return $result;
    }
1230478
protected function getIndex($property, $index = null, $type = null) {
		//verify valid property
		if (!$this->wrappedArg->offsetExists($property))
			throw new \InvalidArgumentException("Unknown property '$property'");
	
		if (is_null($index))
			return $this->castParameter($this->wrappedArg->offsetGet($property), $type);
	
		//check if the value is null
		$value = $this->wrappedArg->offsetGet($property);
		if (is_null($value))
			throw new \InvalidArgumentException("Trying to obtain value from NULL property '$property'");
	
		//check value type
		if (is_array($value)) {
			//search for string index
			if (array_key_exists($index, $value))
				return $this->castParameter($value[$index], $type);
			//try numeric index instead
			elseif (is_numeric($index) && array_key_exists(intval($index), $value))
				return $this->castParameter($value[intval($index)], $type);
	
			throw new \InvalidArgumentException("Index '$index' does not exists in property '$property'");
		}
		//try to convert value to string
		elseif (($value = $this->toString($value)) !== false) {
			//check string length against index
			if ($index < strlen($value))
				return $this->castParameter($value[$index], $type);
	
			throw new \OutOfBoundsException("Index '$index' out of bounds for property '$property'");
		}
			
		throw new \InvalidArgumentException("Cannot obtain index '$index' from a non array/string property '$property'");
	}
372145
public boolean createOrUpdateData(String indexName, String type, String id, Object obj) {
        IndexResponse response = getClient().prepareIndex(indexName, type).setId(id).setSource(Lang.obj2map(obj)).execute().actionGet();
        return response.getResult() == DocWriteResponse.Result.CREATED || response.getResult() == DocWriteResponse.Result.UPDATED;
    }
242989
public function addIndex($type, ...$columns) {
        if (empty($columns)) {
            throw new \InvalidArgumentException("An index must contain at least one column.", 500);
        }

        $type = strtolower($type);

        // Look for a current index row.
        $currentIndex = null;
        foreach ($this->indexes as $i => $index) {
            if ($type !== $index['type']) {
                continue;
            }

            if ($type === Db::INDEX_PK || array_diff($index['columns'], $columns) == []) {
                $currentIndex =& $this->indexes[$i];
                break;
            }
        }

        if ($currentIndex) {
            $currentIndex['columns'] = $columns;
        } else {
            $indexDef = [
                'type' => $type,
                'columns' => $columns,
            ];
            $this->indexes[] = $indexDef;
        }

        return $this;
    }
1284089
public function setId($parameterIndex, ObjectIdInterface $id)
    {
        $this->setParameter($parameterIndex, $this->escape($id->getId()));
    }
189448
public function delete($id, $type) {
		$params = array(
			'id' => $id,
			'type' => $type
		);
		return $this->master->call('files/delete', $params);
	}
64468
public function delete($indexName, $type, $id)
	{
		$index = $this->elasticSearcher->indicesManager()->getRegistered($indexName);

		$params = [
			'index' => $index->getInternalName(),
			'type'  => $type,
			'id'    => $id
		];

		return $this->elasticSearcher->getClient()->delete($params);
	}
244721
public function remove(string $type, int $index)
    {
        if (isset($this->values[$type][$index])) {
            unset($this->values[$type][$index]);

            --$this->valuesCount;
        }

        return $this;
    }
783183
@SuppressWarnings("nls")
    private void indexEntity(String type, String id, XContentBuilder sourceEntity, boolean refresh)
            throws StorageException {
        try {
            String json = sourceEntity.string();
            JestResult response = esClient.execute(new Index.Builder(json).refresh(refresh).index(getIndexName())
                    .setParameter(Parameters.OP_TYPE, "create").type(type).id(id).build());
            if (!response.isSucceeded()) {
                throw new StorageException("Failed to index document " + id + " of type " + type + ": " + response.getErrorMessage());
            }
        } catch (StorageException e) {
            throw e;
        } catch (Exception e) {
            throw new StorageException(e);
        }
    }
299594
public function create($type, Closure $callback, $index = null)
    {
        if (!is_string($type)) {
            throw new InvalidArgumentException('type should be a string');
        }

        if ($index and !is_string($index)) {
            throw new InvalidArgumentException('index should be a string');
        }

        $blueprint = $this->createBlueprint($type, $closure = null, $index);

        $blueprint->create();

        $callback($blueprint);

        $this->build($blueprint);
    }
567262
public IndexResponse sendDataWithObjectMapper(Object sourceObject,
            String index, String type, String id) {
        return sendData(
                JMElasticsearchUtil.buildSourceByJsonMapper(sourceObject),
                index, type, id);
    }
742761
function(index) {
      var that = this;

      return this.readByIndex(index).then(function(doc) {
        return that.delete(doc[that._dbType.id]);
      });
    }