Returns:
            A new ElasticKnnSearch instance.
        """
        index_name = kwargs.get("index_name", str(uuid.uuid4()))
        es_connection = kwargs.get("es_connection")
        es_cloud_id = kwargs.get("es_cloud_id")
        es_user = kwargs.get("es_user")
        es_password = kwargs.get("es_password")
        vector_query_field = kwargs.get("vector_query_field", "vector")
        query_field = kwargs.get("query_field", "text")
        model_id = kwargs.get("model_id")
        dims = kwargs.get("dims")
        if dims is None:
            raise ValueError("ElasticKnnSearch requires 'dims' parameter")
        optional_args = {}
        if vector_query_field is not None:
            optional_args["vector_query_field"] = vector_query_field
        if query_field is not None:
            optional_args["query_field"] = query_field
        knnvectorsearch = cls(
            index_name=index_name,
            embedding=embedding,
            es_connection=es_connection,
            es_cloud_id=es_cloud_id,
            es_user=es_user,
            es_password=es_password,
            **optional_args,
        )
        # Encode the provided texts and add them to the newly created index.
        knnvectorsearch.add_texts(texts, model_id=model_id, dims=dims, **optional_args)
        return knnvectorsearch