Add a document to the index
767153
def add_doc(self, doc, index_update=True, label_guesser_update=True):
        
        if not self.index_writer and index_update:
            self.index_writer = self.index.writer()
        if not self.label_guesser_updater and label_guesser_update:
            self.label_guesser_updater = self.label_guesser.get_updater()
        logger.info("Indexing new doc: %s" % doc)
        if index_update:
            self._update_doc_in_index(self.index_writer, doc)
        if label_guesser_update:
            self.label_guesser_updater.add_doc(doc)
        if doc.docid not in self._docs_by_id:
            self._docs_by_id[doc.docid] = doc
1088819
def add(self, index):
        
        if (index - self.flush_at) < self.interval:
            return
        now = time.time()
        elapsed = now - self.lap
        elapsed_total = now - self.start
        it = index - self.flush_at
        self.lap = now
        if self.verbose:
            logger.info("iter={} {{{}}}={}[sec/{}iter] {}[sec]".format(
                index, self.name, elapsed, it, elapsed_total))
        if self.fd is not None:
            print("{} {} {} {}".format(index, elapsed,
                                       it, elapsed_total), file=self.fd)
        self.flush_at = index
567877
def update(self, index, iterable, commit=True):
        
        parler = False
        # setup here because self.existing_mappings are overridden.
        if not self.setup_complete:
            try:
                self.setup()
            except elasticsearch.TransportError as e:
                if not self.silently_fail:
                    raise

                self.log.error("Failed to add documents to Elasticsearch: %s", e)
                return

        if hasattr(iterable, 'language') and hasattr(iterable.language, '__call__'):
            parler = True  # Django-parler

        for language in self.languages:
            self.index_name = self._index_name_for_language(language)
            # self.log.debug('updating index for {0}'.format(language))
            if parler:
                # workaround for django-parler
                for item in iterable:
                    item.set_current_language(language)
                super(ElasticsearchMultilingualSearchBackend, self).update(
                    index, iterable, commit)
            else:
                with translation.override(language):
                    super(ElasticsearchMultilingualSearchBackend, self).update(
                        index, iterable, commit)
117250
def add_document(self, document):
        '''
        
        '''

        documents_url = urljoin(self.base_url, self.DOCUMENTS_PAGE)
        data = {"corpus": self.url}
        files = {"blob": document}
        result = self.session.post(documents_url, data=data, files=files)
        if result.status_code == 201:
            return Document(session=self.session, **result.json())
        else:
            raise RuntimeError("Document creation failed with status "
                               "{}. The response was: '{}'".format(result.status_code,
                                result.text))
38133
def _index_document(self, document, force=False):
        
        if force:
            self._delete(vid=document['vid'])

        writer = self.index.writer()
        writer.add_document(**document)
        writer.commit()
191677
function (key) {
      if (key === undefined) {
        that.push({
          key: 'DOCUMENT' + sep + docId + sep,
          lastPass: true
        })
        return end()
      }
      that.options.indexes.get(key, function (err, val) {
        if (!err) {
          that.push({
            key: key,
            value: val
          })
        }
        pushValue(docFields[i++])
      })
    }
942475
def _add_to_index(index, obj):
    """"""
    id_set = index.value_map.setdefault(indexed_value(index, obj), set())
    if index.unique:
        if len(id_set) > 0:
            raise UniqueConstraintError()
    id_set.add(obj.id)
503596
public int addDocument(String document) {
    if (root().getNumberOfChildren() >= 0) {
      throw new IllegalStateException("Tree sorting has begun");
    }
    final int index;
    synchronized (this) {
      index = documents.size();
      documents.add(document);
    }
    cursors.addAll(
      IntStream.range(0, document.length() + 1).mapToObj(i -> new CursorData(index, i)).collect(Collectors.toList()));
    nodes.update(0, node -> node.setCursorCount(cursors.length()));
    return index;
  }
62439
private void addToBuffer(String index, String document) {
        if (timerMDC == null) {
            timerMDC = MDC.get("name");
        }
        // Remove old entries from the buffer
        int removedSize = 0;
        if (docBuffer.containsKey(index)) {
            log.debug("Removing buffer duplicate: '{}'", index);
            removedSize = docBuffer.get(index).length();
            docBuffer.remove(index);
        }

        int length = document.length() - removedSize;
        // If this is the first document in the buffer, record its age
        bufferYoungest = new Date().getTime();
        if (docBuffer.isEmpty()) {
            bufferOldest = new Date().getTime();
            log.debug("=== New buffer starting: {}", bufferOldest);
        }
        // Add to the buffer
        docBuffer.put(index, document);
        bufferSize += length;
        // Check if submission is required
        checkBuffer();
    }
494783
public function addToIndex()
    {
        if ($this->isEmpty()) {
            return null;
        }

        $params = array();

        foreach ($this->all() as $item) {
            $params['body'][] = array(
                'index' => array(
                    '_id' => $item->getKey(),
                    '_type' => $item->getTypeName(),
                    '_index' => $item->getIndexName(),
                ),
            );

            $params['body'][] = $item->getIndexDocumentData();
        }

        return $this->getElasticSearchClient()->bulk($params);
    }
1066499
public String addDateDocumentWithId(String indexName, String indexType, Object bean,Object docId) throws ElasticSearchException{
		return addDocumentWithId(this.indexNameBuilder.getIndexName(indexName),   indexType,     bean,docId);
	}
573642
void addDocuments(final Document[] docs) throws IOException
   {
      final IndexWriter writer = getIndexWriter();

      IOException ioExc = null;
      try
      {
         for (Document doc : docs)
         {
            try
            {
               writer.addDocument(doc);
            }
            catch (Throwable e) //NOSONAR
            {
               if (ioExc == null)
               {
                  if (e instanceof IOException)
                  {
                     ioExc = (IOException)e;
                  }
                  else
                  {
                     ioExc = Util.createIOException(e);
                  }
               }

               log.warn("Exception while inverting document", e);
            }
         }
      }
      finally
      {
         invalidateSharedReader();
      }

      if (ioExc != null)
      {
         throw ioExc;
      }
   }
1033336
public  String addDateMapDocument(String indexName,  Map bean) throws ElasticSearchException{
		return addDateMapDocument(  indexName,  _doc,   bean);
	}
852715
def add_documents(self, documents):
        '''
        
        '''
        result, errors = [], []
        for document in documents:
            try:
                result.append(self.add_document(document))
            except RuntimeError as exc:
                errors.append((document, exc))

        return result, errors
638057
public String addDateMapDocument(String indexName, String indexType, Map bean) throws ElasticSearchException{
		return addDocument(  this.indexNameBuilder.getIndexName(indexName),   indexType,   bean,null,null,null,(String )null);
	}
897412
def _index_document(self, document, force=False):
        
        query = text("""
            INSERT INTO dataset_index(vid, title, keywords, doc)
            VALUES(:vid, :title, string_to_array(:keywords, ' '), to_tsvector('english', :doc));
        """)
        self.execute(query, **document)
246047
def put(index_name, doc_type, identifier, body, force, verbose):
    """"""
    result = current_search_client.index(
        index=index_name,
        doc_type=doc_type or index_name,
        id=identifier,
        body=json.load(body),
        op_type='index' if force or identifier is None else 'create',
    )
    if verbose:
        click.echo(json.dumps(result))