# Issue concerning mapping and source

**URL:** <https://discuss.elastic.co/t/issue-concerning-mapping-and-source/18247>\
**Category:** Elasticsearch\
**Created:** [June 22, 2014, 10:00am UTC](https://discuss.elastic.co/t/issue-concerning-mapping-and-source/18247 "2014-06-22T10:00:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phoenix/32/1319_2.png) [@phoenix](https://discuss.elastic.co/u/phoenix)\
**Post date:** [June 22, 2014, 10:00am UTC](https://discuss.elastic.co/t/issue-concerning-mapping-and-source/18247/1 "2014-06-22T10:00:49Z")

</div>

Hi,

I'm trying to index documents in elastic search. I'm using elastic search  
1.2.1, from the Java API.  
My cluster is remote, 3 nodes on 3 servers (one node on each server),  
optimised for indexing (one shard per node, no replication).  
For this, i read a CSV file, from which i generate mapping file.  
For performance reasons, i try to disable \_source, which works, the mapping  
i can read after index creation is correct.  
The thing is after inserting data, i hava nothing in my docs except the id  
generated by ES. If i allow \_source field, i only have my data in the  
\_source field.

Here is how i generate the mapping :

- 

```
       XContentBuilder mapping = jsonBuilder()*

```

- 

```
               .startObject()*

```

- 

```
                   .startObject("record")*

```

- 

```
                       //.startObject("_source").field("enabled", 

```

false).endObject()\*

- 

```
                       .startObject("properties");*

```

- 

```
       for (ColumnMetadata column : 

```

dataset.getMetadata().getColumns()) {\*  
\*  
mapping.startObject(column.geName()).field("type",  
ESColumnTypeHelper.getESType(column.getType())).field("store",  
"yes").field("index", "analyzed").endObject();\*

- 

```
       }*

```

- 

```
                       mapping.endObject()*

```

- 

```
                   .endObject()*

```

- 

```
               .endObject();*

```

Then i create the index :

Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
storeClusterName).build();

- 

```
  CreateIndexRequestBuilder createIndexRequestBuilder = 

```

client.admin().indices().prepareCreate(datasetName).addMapping("record", \*  
_mapping_\*);\*

- 

```
  CreateIndexRequest request = createIndexRequestBuilder.request();*

```

- 

```
  try {*

```

- 

```
      CreateIndexResponse createResponse = 

```

client.admin().indices().create(request).actionGet();\*

- 

```
      if (!createResponse.isAcknowledged()) {*

```

- 

```
          logger.log(Level.SEVERE, "Index creation not 

```

acknowledged.");\*

- 

```
      } else {*

```

- 

```
          logger.log(Level.INFO, "Index creation acknowledged.");*

```

- 

```
      }*

```

- 

```
  } catch (IndexAlreadyExistsException iae) {*

```

- 

```
      logger.log(Level.SEVERE, "Index already exists...");*

```

- 

```
  }*

```

And now how i index using the Bulk API :

- 

```
   BulkRequestBuilder bulkRequest = client.prepareBulk();*

```

- 

```
   try {*

```

- 

```
       logger.log(Level.INFO, "Creating records");*

```

- 

```
       for (Record record : records) {*

```

- 

```
           IndexRequestBuilder builder = 

```

client.prepareIndex(datasetName, "record");\*

- 

```
           XContentBuilder data = jsonBuilder();*

```

- 

```
           data.startObject();*

```

- 

```
           for (ColumnMetadata column : 

```

dataset.getMetadata().getColumns()) {\*

- 

```
               Object value = 

```

record.getCell(column.getName()).getValue();\*

- 

```
               if (value == null || (value instanceof String && 

```

value.equals("NULL"))) {\*

- 

```
                   value = null;*

```

- 

```
               }*

```

- 

```
               data.field(column.getNormalizedName(), value);*

```

- 

```
           }*

```

- 

```
           data.endObject();*

```

- 

```
           builder.setSource(data);*

```

- 

```
           bulkRequest.add(builder);*

```

- 

```
           logger.log(Level.INFO, "Creating records");*

```

- 

```
       }*

```

- 

```
       logger.log(Level.INFO, "Created "+ 

```

bulkRequest.numberOfActions() +" records");\*

- 

```
       BulkResponse bulkResponse = bulkRequest.execute().actionGet();*

```

- 

```
       if (bulkResponse.hasFailures()) {*

```

- 

```
           logger.log(Level.SEVERE, "Could not index : " + 

```

bulkResponse.buildFailureMessage());\*

- 

```
       }*

```

Now for the resulting data. First the mapping i read using cURL (in this  
one, i allow \_default) :

_curl -XGET '[http://myserver:9200/realestateagencies/\_mapping/record](http://myserver:9200/realestateagencies/_mapping/record)'_

\*{ "realestateagencies" : \*

- { "mappings" : \*
- 

```
   { "record" : *

```

- 

```
       { "properties" : *

```

- 

```
           {*

```

- 

```
             "agencystatus" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "cardnumber" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "city_id" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "companyname" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

_[REMOVED SOME MAPPING TO SHORTEN DISPLAY]_

- 

```
             "streetlabel" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "streetnumber" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "streetnumbercomplement" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "streettype" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "summarizedagency_id" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "updatedate" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               },*

```

- 

```
             "websiteurl" : { "store" : true,*

```

- 

```
                 "type" : "string"*

```

- 

```
               }*

```

- 

```
           } *

```

- 

```
       }*

```

- 

```
    }*

```

- 

```
}*

```

- }\*

Can't see any indexed field in my mapping, even i explicitly gave it a  
value in my mapping ( _.field("index", "analyzed")_ ), but i suppose it's  
because index : analyzed is the default value.  
After that, the result of a query on my index type gives this :

_{_

- _took: 7_
- _timed\_out: false_
- _\_shards: {_
  - _total: 3_
  - _successful: 3_
  - _failed: 0_  
_}_

- _hits: {_
  - _total: 100000_
  - _max\_score: 1_
  - _hits: [_
    - _{_
      - _\_index: realestateagencies_
      - _\_type: record_
      - _\_id: c2yWW2S3TyKkJGGFpgVS4g_
      - _\_score: 1_
      - _\_source: {_
        - _id: 83163_
        - _crawlsource: 1_
        - _deletedate: null_
        - _updatedate: null_
        - _dealerkind: 1_
        - _email: null_
        - _name: Agence Principale - Colombes_
        - _phonenumber: 0142423333_
        - _latitude: 0_
        - _longitude: 0_
        - _normalized: 6RUEGABRIELPERI92700COLOMBES_
        - _original: - 6 RUE GABRIEL PERI 92700 COLOMBES_
        - _street1: 6 rue Gabriel Peri_
        - _street2: null_
        - _streetlabel: Gabriel Peri_
        - _streetnumber: 6_
        - _streetnumbercomplement: 0_
        - _streettype: 20_
        - _cardnumber: null_
        - _companyname: null_
        - _createdate: 1969-12-31T23:00:00.000Z_
        - _faxnumber: null_
        - _logourl: null_
        - _normalizedname: AGENCEPRINCIPALECOLOMBES_
        - _rcsnumber: null_
        - _sirennumber: 450499298_
        - _siretnumber: null_
        - _websiteurl: null_
        - _agencystatus: 1_
        - _keyperportal: 484737|AGENCEPRINCIPALECOLOMBES_
        - _reconciliationpolicy: 1_
        - _city\_id: 17988_
        - _summarizedagency\_id: 408837_  
_}_  
_},_ [REST IS REMOVED]

And of course if I disable \_source field, resulting docs are empty.

I cannot see what i'm doing wrong here. Anyone can see something wrong ?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 23, 2014, 2:05pm UTC](https://discuss.elastic.co/t/issue-concerning-mapping-and-source/18247/2 "2014-06-23T14:05:00Z")

</div>

What exactly is the issue? Are you getting back results, just with no data?  
By default, a query will only return the \_source field. If you want to  
return other stored fields, then you would need to explicit name them:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Also, disabling source does not necessarily increase performance. Lucene  
would need to execute a seek for each individual field instead of just one  
for the source. If you are request numerous fields, then using stored  
fields actually decreases performance. It all depends on the size of your  
document/fields and the number of fields used.

Cheers,

Ivan

On Sun, Jun 22, 2014 at 3:00 AM, Frederic Esnault \<  
[esnault.frederic@gmail.com](mailto:esnault.frederic@gmail.com)\> wrote:

> Hi,
> 
> I'm trying to index documents in Elasticsearch. I'm using Elasticsearch  
> 1.2.1, from the Java API.  
> My cluster is remote, 3 nodes on 3 servers (one node on each server),  
> optimised for indexing (one shard per node, no replication).  
> For this, i read a CSV file, from which i generate mapping file.  
> For performance reasons, i try to disable \_source, which works, the  
> mapping i can read after index creation is correct.  
> The thing is after inserting data, i hava nothing in my docs except the id  
> generated by ES. If i allow \_source field, i only have my data in the  
> \_source field.
> 
> Here is how i generate the mapping :
> 
> - 
> 
> ```
> XContentBuilder mapping = jsonBuilder()*
> 
> ```
> 
> - 
> 
> ```
> .startObject()*
> 
> ```
> 
> - 
> 
> ```
> .startObject("record")*
> 
> ```
> 
> - 
> 
> ```
> //.startObject("_source").field("enabled",
> 
> ```
> 
> false).endObject()\*
> 
> - 
> 
> ```
> .startObject("properties");*
> 
> ```
> 
> - 
> 
> ```
> for (ColumnMetadata column :
> 
> ```
> 
> dataset.getMetadata().getColumns()) {\*  
> \*  
> mapping.startObject(column.geName()).field("type",  
> ESColumnTypeHelper.getESType(column.getType())).field("store",  
> "yes").field("index", "analyzed").endObject();\*
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> mapping.endObject()*
> 
> ```
> 
> - 
> 
> ```
> .endObject()*
> 
> ```
> 
> - 
> 
> ```
> .endObject();*
> 
> ```
> 
> Then i create the index :
> 
> Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
> storeClusterName).build();
> 
> - 
> 
> ```
> CreateIndexRequestBuilder createIndexRequestBuilder =
> 
> ```
> 
> client.admin().indices().prepareCreate(datasetName).addMapping("record", \*  
> _mapping_\*);\*
> 
> - 
> 
> ```
> CreateIndexRequest request = createIndexRequestBuilder.request();*
> 
> ```
> 
> - 
> 
> ```
> try {*
> 
> ```
> 
> - 
> 
> ```
> CreateIndexResponse createResponse =
> 
> ```
> 
> client.admin().indices().create(request).actionGet();\*
> 
> - 
> 
> ```
> if (!createResponse.isAcknowledged()) {*
> 
> ```
> 
> - 
> 
> ```
> logger.log(Level.SEVERE, "Index creation not
> 
> ```
> 
> acknowledged.");\*
> 
> - 
> 
> ```
> } else {*
> 
> ```
> 
> - 
> 
> ```
> logger.log(Level.INFO, "Index creation acknowledged.");*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> } catch (IndexAlreadyExistsException iae) {*
> 
> ```
> 
> - 
> 
> ```
> logger.log(Level.SEVERE, "Index already exists...");*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> And now how i index using the Bulk API :
> 
> - 
> 
> ```
> BulkRequestBuilder bulkRequest = client.prepareBulk();*
> 
> ```
> 
> - 
> 
> ```
> try {*
> 
> ```
> 
> - 
> 
> ```
> logger.log(Level.INFO, "Creating records");*
> 
> ```
> 
> - 
> 
> ```
> for (Record record : records) {*
> 
> ```
> 
> - 
> 
> ```
> IndexRequestBuilder builder =
> 
> ```
> 
> client.prepareIndex(datasetName, "record");\*
> 
> - 
> 
> ```
> XContentBuilder data = jsonBuilder();*
> 
> ```
> 
> - 
> 
> ```
> data.startObject();*
> 
> ```
> 
> - 
> 
> ```
> for (ColumnMetadata column :
> 
> ```
> 
> dataset.getMetadata().getColumns()) {\*
> 
> - 
> 
> ```
> Object value =
> 
> ```
> 
> record.getCell(column.getName()).getValue();\*
> 
> - 
> 
> ```
> if (value == null || (value instanceof String &&
> 
> ```
> 
> value.equals("NULL"))) {\*
> 
> - 
> 
> ```
> value = null;*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> data.field(column.getNormalizedName(), value);*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> data.endObject();*
> 
> ```
> 
> - 
> 
> ```
> builder.setSource(data);*
> 
> ```
> 
> - 
> 
> ```
> bulkRequest.add(builder);*
> 
> ```
> 
> - 
> 
> ```
> logger.log(Level.INFO, "Creating records");*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> logger.log(Level.INFO, "Created "+
> 
> ```
> 
> bulkRequest.numberOfActions() +" records");\*
> 
> - 
> 
> ```
> BulkResponse bulkResponse =
> 
> ```
> 
> bulkRequest.execute().actionGet();\*
> 
> - 
> 
> ```
> if (bulkResponse.hasFailures()) {*
> 
> ```
> 
> - 
> 
> ```
> logger.log(Level.SEVERE, "Could not index : " +
> 
> ```
> 
> bulkResponse.buildFailureMessage());\*
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> Now for the resulting data. First the mapping i read using cURL (in this  
> one, i allow \_default) :
> 
> _curl -XGET '[http://myserver:9200/realestateagencies/\_mapping/record](http://myserver:9200/realestateagencies/_mapping/record)  
> [http://myserver:9200/realestateagencies/\_mapping/record](http://myserver:9200/realestateagencies/_mapping/record)'_
> 
> \*{ "realestateagencies" : \*
> 
> - { "mappings" : \*
> - 
> 
> ```
> { "record" : *
> 
> ```
> 
> - 
> 
> ```
> { "properties" : *
> 
> ```
> 
> - 
> 
> ```
> {*
> 
> ```
> 
> - 
> 
> ```
> "agencystatus" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "cardnumber" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "city_id" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "companyname" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> _[REMOVED SOME MAPPING TO SHORTEN DISPLAY]_
> 
> - 
> 
> ```
> "streetlabel" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "streetnumber" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "streetnumbercomplement" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "streettype" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "summarizedagency_id" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "updatedate" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> },*
> 
> ```
> 
> - 
> 
> ```
> "websiteurl" : { "store" : true,*
> 
> ```
> 
> - 
> 
> ```
> "type" : "string"*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> } *
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - 
> 
> ```
> }*
> 
> ```
> 
> - }\*
> 
> Can't see any indexed field in my mapping, even i explicitly gave it a  
> value in my mapping ( _.field("index", "analyzed")_ ), but i suppose it's  
> because index : analyzed is the default value.  
> After that, the result of a query on my index type gives this :
> 
> _{_
> 
> - _took: 7_
> - _timed\_out: false_
> - _\_shards: {_
> - _total: 3_
> - _successful: 3_
> - _failed: 0_  
> _}_
> 
> - _hits: {_
> - _total: 100000_
> - _max\_score: 1_
> - _hits: [_
> - _{_
> - _\_index: realestateagencies_
> - _\_type: record_
> - _\_id: c2yWW2S3TyKkJGGFpgVS4g_
> - _\_score: 1_
> - _\_source: {_
> - _id: 83163_
> - _crawlsource: 1_
> - _deletedate: null_
> - _updatedate: null_
> - _dealerkind: 1_
> - _email: null_
> - _name: Agence Principale - Colombes_
> - _phonenumber: 0142423333_
> - _latitude: 0_
> - _longitude: 0_
> - _normalized: 6RUEGABRIELPERI92700COLOMBES_
> - _original: - 6 RUE GABRIEL PERI 92700 COLOMBES_
> - _street1: 6 rue Gabriel Peri_
> - _street2: null_
> - _streetlabel: Gabriel Peri_
> - _streetnumber: 6_
> - _streetnumbercomplement: 0_
> - _streettype: 20_
> - _cardnumber: null_
> - _companyname: null_
> - _createdate: 1969-12-31T23:00:00.000Z_
> - _faxnumber: null_
> - _logourl: null_
> - _normalizedname: AGENCEPRINCIPALECOLOMBES_
> - _rcsnumber: null_
> - _sirennumber: 450499298_
> - _siretnumber: null_
> - _websiteurl: null_
> - _agencystatus: 1_
> - _keyperportal: 484737|AGENCEPRINCIPALECOLOMBES_
> - _reconciliationpolicy: 1_
> - _city\_id: 17988_
> - _summarizedagency\_id: 408837_  
> _}_  
> _},_ [REST IS REMOVED]
> 
> And of course if I disable \_source field, resulting docs are empty.
> 
> I cannot see what i'm doing wrong here. Anyone can see something wrong ?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAKhqpqi4VO5-VgD77awMgiKifpvW9f7O4-JJnUizs64g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAKhqpqi4VO5-VgD77awMgiKifpvW9f7O4-JJnUizs64g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![phoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phoenix/32/1319_2.png) [@phoenix](https://discuss.elastic.co/u/phoenix)\
**Post date:** [June 24, 2014, 11:36am UTC](https://discuss.elastic.co/t/issue-concerning-mapping-and-source/18247/3 "2014-06-24T11:36:45Z")

</div>

Hi Ivan, thanks for all this.  
I was getting results but without my fields. Knowing what you told me about  
default behaviour of queries to only return source, this all makes sense  
now.  
Actually i was thinking of disabling source for indexing performance boost.  
But if i loose performance afterwards, this seems not a good idea.

Thanks a lot !

Le lundi 23 juin 2014 16:05:06 UTC+2, Ivan Brusic a écrit :

> What exactly is the issue? Are you getting back results, just with no  
> data? By default, a query will only return the \_source field. If you want  
> to return other stored fields, then you would need to explicit name them:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-fields.html#search-request-fields)
> 
> Also, disabling source does not necessarily increase performance. Lucene  
> would need to execute a seek for each individual field instead of just one  
> for the source. If you are request numerous fields, then using stored  
> fields actually decreases performance. It all depends on the size of your  
> document/fields and the number of fields used.
> 
> Cheers,
> 
> Ivan
> 
> On Sun, Jun 22, 2014 at 3:00 AM, Frederic Esnault \<[esnault....@gmail.com](mailto:esnault....@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I'm trying to index documents in Elasticsearch. I'm using Elasticsearch  
> > 1.2.1, from the Java API.  
> > My cluster is remote, 3 nodes on 3 servers (one node on each server),  
> > optimised for indexing (one shard per node, no replication).  
> > For this, i read a CSV file, from which i generate mapping file.  
> > For performance reasons, i try to disable \_source, which works, the  
> > mapping i can read after index creation is correct.  
> > The thing is after inserting data, i hava nothing in my docs except the  
> > id generated by ES. If i allow \_source field, i only have my data in the  
> > \_source field.
> > 
> > Here is how i generate the mapping :
> > 
> > - 
> > 
> > ```
> > XContentBuilder mapping = jsonBuilder()*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .startObject()*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .startObject("record")*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > //.startObject("_source").field("enabled", 
> > 
> > ```
> > 
> > false).endObject()\*
> > 
> > - 
> > 
> > ```
> > .startObject("properties");*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > for (ColumnMetadata column : 
> > 
> > ```
> > 
> > dataset.getMetadata().getColumns()) {\*  
> > \*  
> > mapping.startObject(column.geName()).field("type",  
> > ESColumnTypeHelper.getESType(column.getType())).field("store",  
> > "yes").field("index", "analyzed").endObject();\*
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > mapping.endObject()*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .endObject()*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .endObject();*
> > 
> > ```
> > 
> > Then i create the index :
> > 
> > Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
> > storeClusterName).build();
> > 
> > - 
> > 
> > ```
> > CreateIndexRequestBuilder createIndexRequestBuilder = 
> > 
> > ```
> > 
> > client.admin().indices().prepareCreate(datasetName).addMapping("record", \*  
> > _mapping_\*);\*
> > 
> > - 
> > 
> > ```
> > CreateIndexRequest request = createIndexRequestBuilder.request();*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > try {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > CreateIndexResponse createResponse = 
> > 
> > ```
> > 
> > client.admin().indices().create(request).actionGet();\*
> > 
> > - 
> > 
> > ```
> > if (!createResponse.isAcknowledged()) {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > logger.log(Level.SEVERE, "Index creation not 
> > 
> > ```
> > 
> > acknowledged.");\*
> > 
> > - 
> > 
> > ```
> > } else {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > logger.log(Level.INFO, "Index creation acknowledged.");*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > } catch (IndexAlreadyExistsException iae) {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > logger.log(Level.SEVERE, "Index already exists...");*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > And now how i index using the Bulk API :
> > 
> > - 
> > 
> > ```
> > BulkRequestBuilder bulkRequest = client.prepareBulk();*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > try {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > logger.log(Level.INFO, "Creating records");*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > for (Record record : records) {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > IndexRequestBuilder builder = 
> > 
> > ```
> > 
> > client.prepareIndex(datasetName, "record");\*
> > 
> > - 
> > 
> > ```
> > XContentBuilder data = jsonBuilder();*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > data.startObject();*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > for (ColumnMetadata column : 
> > 
> > ```
> > 
> > dataset.getMetadata().getColumns()) {\*
> > 
> > - 
> > 
> > ```
> > Object value = 
> > 
> > ```
> > 
> > record.getCell(column.getName()).getValue();\*
> > 
> > - 
> > 
> > ```
> > if (value == null || (value instanceof String && 
> > 
> > ```
> > 
> > value.equals("NULL"))) {\*
> > 
> > - 
> > 
> > ```
> > value = null;*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > data.field(column.getNormalizedName(), value);*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > data.endObject();*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > builder.setSource(data);*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > bulkRequest.add(builder);*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > logger.log(Level.INFO, "Creating records");*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > logger.log(Level.INFO, "Created "+ 
> > 
> > ```
> > 
> > bulkRequest.numberOfActions() +" records");\*
> > 
> > - 
> > 
> > ```
> > BulkResponse bulkResponse = 
> > 
> > ```
> > 
> > bulkRequest.execute().actionGet();\*
> > 
> > - 
> > 
> > ```
> > if (bulkResponse.hasFailures()) {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > logger.log(Level.SEVERE, "Could not index : " + 
> > 
> > ```
> > 
> > bulkResponse.buildFailureMessage());\*
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > Now for the resulting data. First the mapping i read using cURL (in this  
> > one, i allow \_default) :
> > 
> > \*curl -XGET '[http://myserver:9200/realestateagencies/\_mapping/record](http://myserver:9200/realestateagencies/_mapping/record)  
> > [http://myserver:9200/realestateagencies/\_mapping/record](http://myserver:9200/realestateagencies/_mapping/record)' \*
> > 
> > \*{ "realestateagencies" : \*
> > 
> > - { "mappings" : \*
> > - 
> > 
> > ```
> > { "record" : *
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > { "properties" : *
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > {*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "agencystatus" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "cardnumber" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "city_id" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "companyname" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > _[REMOVED SOME MAPPING TO SHORTEN DISPLAY]_
> > 
> > - 
> > 
> > ```
> > "streetlabel" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "streetnumber" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "streetnumbercomplement" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "streettype" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "summarizedagency_id" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "updatedate" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > },*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "websiteurl" : { "store" : true,*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > "type" : "string"*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > } *
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > }*
> > 
> > ```
> > 
> > - }\*
> > 
> > Can't see any indexed field in my mapping, even i explicitly gave it a  
> > value in my mapping ( _.field("index", "analyzed")_ ), but i suppose  
> > it's because index : analyzed is the default value.  
> > After that, the result of a query on my index type gives this :
> > 
> > _{_
> > 
> > - _took: 7_
> > - _timed\_out: false_
> > - _\_shards: {_
> > - _total: 3_
> > - _successful: 3_
> > - _failed: 0_  
> > _}_
> > 
> > - _hits: {_
> > - _total: 100000_
> > - _max\_score: 1_
> > - _hits: [_
> > - _{_
> > - _\_index: realestateagencies_
> > - _\_type: record_
> > - _\_id: c2yWW2S3TyKkJGGFpgVS4g_
> > - _\_score: 1_
> > - _\_source: {_
> > - _id: 83163_
> > - _crawlsource: 1_
> > - _deletedate: null_
> > - _updatedate: null_
> > - _dealerkind: 1_
> > - _email: null_
> > - _name: Agence Principale - Colombes_
> > - _phonenumber: 0142423333_
> > - _latitude: 0_
> > - _longitude: 0_
> > - _normalized: 6RUEGABRIELPERI92700COLOMBES_
> > - _original: - 6 RUE GABRIEL PERI 92700 COLOMBES_
> > - _street1: 6 rue Gabriel Peri_
> > - _street2: null_
> > - _streetlabel: Gabriel Peri_
> > - _streetnumber: 6_
> > - _streetnumbercomplement: 0_
> > - _streettype: 20_
> > - _cardnumber: null_
> > - _companyname: null_
> > - _createdate: 1969-12-31T23:00:00.000Z_
> > - _faxnumber: null_
> > - _logourl: null_
> > - _normalizedname: AGENCEPRINCIPALECOLOMBES_
> > - _rcsnumber: null_
> > - _sirennumber: 450499298_
> > - _siretnumber: null_
> > - _websiteurl: null_
> > - _agencystatus: 1_
> > - _keyperportal: 484737|AGENCEPRINCIPALECOLOMBES_
> > - _reconciliationpolicy: 1_
> > - _city\_id: 17988_
> > - _summarizedagency\_id: 408837_  
> > _}_  
> > _},_ [REST IS REMOVED]
> > 
> > And of course if I disable \_source field, resulting docs are empty.
> > 
> > I cannot see what i'm doing wrong here. Anyone can see something wrong ?
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d226606c-fbb4-4167-87ec-92f2f8fe7728%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7637fe2d-9de8-49ef-bf5b-1e65890c2059%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7637fe2d-9de8-49ef-bf5b-1e65890c2059%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:20am UTC](https://discuss.elastic.co/t/issue-concerning-mapping-and-source/18247/4 "2017-07-06T01:20:13Z")

</div>


