def index(self, doc, index, doc_type, id=None, parent=None, force_insert=False,<EOL>op_type=None, bulk=False, version=None, querystring_args=None, ttl=None):
if querystring_args is None:<EOL><INDENT>querystring_args = {}<EOL><DEDENT>if bulk:<EOL><INDENT>if op_type is None:<EOL><INDENT>op_type = "<STR_LIT:index>"<EOL><DEDENT>if force_insert:<EOL><INDENT>op_type = "<STR_LIT>"<EOL><DEDENT>cmd = {op_type: {"<STR_LIT>": index, "<STR_LIT>": doc_type}}<EOL>if parent:<EOL><INDENT>cmd[op_type]['<STR_LIT>'] = parent<EOL><DEDENT>if version:<EOL><INDENT>cmd[op_type]['<STR_LIT>'] = version<EOL><DEDENT>if '<STR_LIT>' in querystring_args:<EOL><INDENT>cmd[op_type]['<STR_LIT>'] = querystring_args['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in querystring_args:<EOL><INDENT>cmd[op_type]['<STR_LIT>'] = querystring_args['<STR_LIT>']<EOL><DEDENT>if id is not None:  <EOL><INDENT>cmd[op_type]['<STR_LIT>'] = id<EOL><DEDENT>if ttl is not None:<EOL><INDENT>cmd[op_type]['<STR_LIT>'] = ttl<EOL><DEDENT>if isinstance(doc, dict):<EOL><INDENT>doc = json.dumps(doc, cls=self.encoder)<EOL><DEDENT>command = "<STR_LIT>" % (json.dumps(cmd, cls=self.encoder), doc)<EOL>self.bulker.add(command)<EOL>return self.flush_bulk()<EOL><DEDENT>if force_insert:<EOL><INDENT>querystring_args['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>if op_type:<EOL><INDENT>querystring_args['<STR_LIT>'] = op_type<EOL><DEDENT>if parent:<EOL><INDENT>if not isinstance(parent, str):<EOL><INDENT>parent = str(parent)<EOL><DEDENT>querystring_args['<STR_LIT>'] = parent<EOL><DEDENT>if version:<EOL><INDENT>if not isinstance(version, str):<EOL><INDENT>version = str(version)<EOL><DEDENT>querystring_args['<STR_LIT:version>'] = version<EOL><DEDENT>if ttl is not None:<EOL><INDENT>if not isinstance(ttl, str):<EOL><INDENT>ttl = str(ttl)<EOL><DEDENT>querystring_args['<STR_LIT>'] = ttl<EOL><DEDENT>if id is None:<EOL><INDENT>request_method = '<STR_LIT:POST>'<EOL><DEDENT>else:<EOL><INDENT>request_method = '<STR_LIT>'<EOL><DEDENT>path = make_path(index, doc_type, id)<EOL>return self._send_request(request_method, path, doc, querystring_args)<EOL>
Index a typed JSON document into a specific index and make it searchable.