Index a document within a mapping type.

@param indexName
@param mappingName
@param key
@param value
@throws Exception
964157
@When("^I index a document in the index named '(.+?)' using the mapping named '(.+?)' with key '(.+?)' and value '(.+?)'$")
    public void indexElasticsearchDocument(String indexName, String mappingName, String key, String value) throws Exception {
        ArrayList<XContentBuilder> mappingsource = new ArrayList<XContentBuilder>();
        XContentBuilder builder = jsonBuilder().startObject().field(key, value).endObject();
        mappingsource.add(builder);
        commonspec.getElasticSearchClient().createMapping(indexName, mappingName, mappingsource);
    }
297455
protected void setIndexedProperty(Object bean, String name, int[] indexes, Object value, FormMappingOption option) { // e.g. sea[0]
        final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(bean.getClass());
        if (!beanDesc.hasPropertyDesc(name)) {
            return;
        }
        final PropertyDesc pd = beanDesc.getPropertyDesc(name);
        if (!pd.isWritable()) {
            return;
        }
        if (value.getClass().isArray() && Array.getLength(value) > 0) {
            value = Array.get(value, 0);
        }
        final Class<?> propertyType = pd.getPropertyType();
        if (propertyType.isArray()) {
            Object array = pd.getValue(bean);
            final Class<?> elementType = getArrayElementType(propertyType, indexes.length);
            if (array == null) {
                int[] newIndexes = new int[indexes.length];
                newIndexes[0] = indexes[0] + 1;
                array = Array.newInstance(elementType, newIndexes);
            }
            array = expand(array, indexes, elementType);
            pd.setValue(bean, array);
            setArrayValue(array, indexes, value);
        } else { // e.g. List, ImmutableList, MutableList
            // process of your collections should be first because MutableList is java.util.List 
            final Optional<FormYourCollectionResource> yourCollection = findListableYourCollection(pd, option);
            if (yourCollection.isPresent()) { // e.g. ImmutableList, MutableList
                doSetIndexedPropertyListable(bean, name, indexes, value, beanDesc, pd, option, newList -> {
                    @SuppressWarnings("unchecked")
                    final List<Object> filtered = (List<Object>) yourCollection.get().getYourCollectionCreator().apply(newList);
                    return filtered;
                });
            } else if (List.class.isAssignableFrom(propertyType)) {
                doSetIndexedPropertyListable(bean, name, indexes, value, beanDesc, pd, option, Function.identity());
            } else {
                throwIndexedPropertyNotListArrayException(beanDesc, pd);
            }
        }
    }
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);
	}
1005423
public static void mapping(String mappedFieldName, String mappedClassName, String targetClassName){
		throw new MappingErrorException(MSG.INSTANCE.message(mappingErrorException3,mappedFieldName,mappedClassName,targetClassName));
	}
192891
public void map(DocumentID key, LineDocTextAndOp value,
      OutputCollector<DocumentID, DocumentAndOp> output, Reporter reporter)
      throws IOException {

    DocumentAndOp.Op op = value.getOp();
    Document doc = null;
    Term term = null;

    if (op == DocumentAndOp.Op.INSERT || op == DocumentAndOp.Op.UPDATE) {
      doc = new Document();
      doc.add(new Field(docidFieldName, key.getText().toString(),
          Field.Store.YES, Field.Index.UN_TOKENIZED));
      doc.add(new Field(contentFieldName, value.getText().toString(),
          Field.Store.NO, Field.Index.TOKENIZED));
    }

    if (op == DocumentAndOp.Op.DELETE || op == DocumentAndOp.Op.UPDATE) {
      term = new Term(docidFieldName, key.getText().toString());
    }

    output.collect(key, new DocumentAndOp(op, doc, term));
  }
636982
public void ensureIndex(DBObject keys, String name) throws MongoException {
        ensureIndex(keys, name, false);
    }
240196
public static final IndexReference indexRef(String indexName, IndexType type) {
        if (type == null) {
            return new IndexReference("`" + indexName + "`");
        }
        return new IndexReference("`" + indexName + "` USING " + type.toString());
    }
104457
public   String getDocument(String indexName,   String documentId, Map<String, Object> options) throws ElasticSearchException{
		return getDocument(  indexName,  _doc,     documentId,   options);
	}
641823
public void index(String indexName, String indexType, Map<CharSequence, CharSequence> idJsonMap) {
        index(
                idJsonMap.entrySet().stream()
                        .map(entry -> new IndexRequest.IndexRequestBuilder(indexName, indexType, entry.getValue().toString())
                                .withId(entry.getKey().toString()).build()
                        )
                        .collect(toList())
        );
    }
1184135
private static String mappingKey(Map<String, String> mapping, String fieldName) {
		if (MapUtil.isEmpty(mapping)) {
			return fieldName;
		}
		return ObjectUtil.defaultIfNull(mapping.get(fieldName), fieldName);
	}
82486
private void mapAndRememberIndexFile(File index) {
        MappedFileReader idxFileReader = null;
        try {
            idxFileReader = new MappedFileReader(index);
            mappedIndexFileReader.add(idxFileReader);
            indexFiles.add(idxFileReader.map());
        } catch(IOException e) {
            logger.error("Error mmapping " + index, e);
        }
    }
1124977
public   String getDocument(String indexName,  String documentId) throws ElasticSearchException{
		return getDocument(  indexName,  _doc,  documentId);
	}
599758
public function setIndex(Index $index)
    {
        if ($this->isEmbeddedDocument) {
            throw MappingException::embeddedDocumentsNotIndexable($this->getName());
        }

        if ($this->index !== null) {
            throw MappingException::indexExists($this->getName(), 'primary');
        }

        $this->index = $index;
    }
1085886
private static void createTypeWithMappingInElasticsearch(RestHighLevelClient client, String index, String mapping)
            throws Exception {
        logger.trace("createTypeWithMappingInElasticsearch([{}])", index);

        assert client != null;
        assert index != null;

        if (mapping != null) {
            // Create mapping
            client.indices().putMapping(new PutMappingRequest(index).source(mapping, XContentType.JSON), RequestOptions.DEFAULT);
        } else {
            logger.trace("no content given for mapping. Ignoring mapping creation in index [{}].", index);
        }

        logger.trace("/createTypeWithMappingInElasticsearch([{}])", index);
    }
1029482
public   String addDocumentWithId(String indexName,  Object bean, Object docId, Object parentId) throws ElasticSearchException{
		return addDocumentWithId(  indexName,  _doc,  bean,   docId,   parentId);
	}
1191521
private void addIndex(final String index) throws IOException {

        logger.info("Adding index '{}'...", index);

        String resourcePath = "/" + index;

        if (doesResourceNotExist(resourcePath)) {

            try {
                elasticSearchAdminClient.performRequest(HttpMethod.PUT, resourcePath);

                logger.info("Added '{}' index", index);
            } catch (ResponseException e) {

                boolean errorCreatingIndex = true;

                Response errorResponse = e.getResponse();
                if (errorResponse.getStatusLine().getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
                    JsonNode root = objectMapper.readTree(EntityUtils.toString(errorResponse.getEntity()));
                    String errorCode = root.get("error").get("type").asText();
                    if ("index_already_exists_exception".equals(errorCode)) {
                        errorCreatingIndex = false;
                    }
                }

                if (errorCreatingIndex) {
                    throw e;
                }
            }
        } else {
            logger.info("Index '{}' already exists", index);
        }
    }
223669
void indexProperty(AnnotationValue<?> annotation, String property, @Nullable String value) {
        indexes.computeIfAbsent(property, s -> new HashSet<>(2)).add(new AnnotationValueIndex(annotation, property, value));
    }