# Issue with saving an object to ES

**URL:** <https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179>\
**Category:** Elasticsearch\
**Created:** [January 26, 2018, 9:56am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179 "2018-01-26T09:56:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 26, 2018, 9:56am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/1 "2018-01-26T09:56:53Z")

</div>

Try to save object due to such json:

```
{
	"header": "test Header",
	"timeStamp":"2018-01-26T09:45:00.000+02:00",
	"message":"test message 3",
	"level":"INFO",
	"node": "first node",
	"system": "super system 1",
	"port": 9300,
	"module":"test module",
	"submodule":"test submodule",
	"thread":"test thread",
	"operation":"some operation",
	"sessionId":"1",
	"userLogin":"user",
	"userName":"user",
	"office":"1",
    "location": { 
    "lat": 41.12,
    "lon": -71.34
     },
	"ip":"192.168.3.93",
	"device":"some device"
}

```

And get such error:

```
{
    "timestamp": "26.01.2018",
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.elasticsearch.ElasticsearchStatusException",
    "message": "Elasticsearch exception [type=illegal_argument_exception, reason=[location] is defined as an object in mapping [logs_info] but this name is already used for a field in other types]",
    "path": "/api/saveLogs"
}

```

Right know I don't have any indexes in my ES, deleted all.  
What it can be?

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 26, 2018, 10:03am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/2 "2018-01-26T10:03:30Z")

</div>

Can you show what you get when running this command?

```
curl -XGET localhost:9200/_cat/indices?v
```

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 26, 2018, 10:07am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/3 "2018-01-26T10:07:35Z")

</div>

```
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana mXFRna9FRm2_1p9mzT4LeA 1 1 4 0 35.1kb 17.5kb
green open portal-logs-26.01.2018 Uyxwau6vRiGaU2ovJwfjMg 5 1 0 0 2.2kb 1.1kb
```

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 26, 2018, 10:10am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/4 "2018-01-26T10:10:01Z")

</div>

I've added also such pattern:

```
PUT _template/portal-logs
{
  "index_patterns": "portal-logs-*",
  "settings": { "number_of_shards": 5 },
  "mappings": {
    "ENTRY": {
      "_source": { "enabled": true },
      "_all": { "enabled": false },
      "properties": {
        "timestamp": {"type": "date"},
        "header": {"type": "keyword"},
        "message": {"type": "text"},
        "level": {"type": "text"},
        "node": {"type": "text"},
        "system": {"type": "text"},
        "port": {"type": "integer"},
        "module": {"type": "text"},
        "submodule": {"type": "text"},
        "thread": {"type": "text"},
        "operation": {"type": "text"},
        "sessionId": {"type": "text"},
        "userLogin": {"type": "text"},
        "userName": {"type": "text"},
        "office": {"type": "text"},
        "location":{"type": "geo_point"},
        "ip":{"type": "text"},
        "device": {"type": "text"}
      }
    }
  }
}

```

but without it the error is the same.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 26, 2018, 10:17am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/5 "2018-01-26T10:17:16Z")

</div>

Which version of ES are you running and can you show the command you're using to index your data?

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 26, 2018, 10:18am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/6 "2018-01-26T10:18:23Z")

</div>

ES 6.1  
Here my method for indexing documents:

```
@PostMapping("/saveLogs")
    @Transactional
    public GenericResponse<?> saveLogsToES(@RequestBody ElasticSearchLogs elasticSearchLogs) {

        String date = new SimpleDateFormat("dd.MM.yyyy").format(new Date()).toLowerCase();
        try {
            XContentBuilder builder = jsonBuilder()
            .startObject()
                .field("timeStamp", elasticSearchLogs.getTimeStamp())
                .field("header", elasticSearchLogs.getHeader())
                .field("message", elasticSearchLogs.getMessage())
                .field("level", elasticSearchLogs.getLevel())
                .field("node", elasticSearchLogs.getNode())
                .field("system", elasticSearchLogs.getSystem())
                .field("port", elasticSearchLogs.getPort())
                .field("module", elasticSearchLogs.getModule())
                .field("submodule", elasticSearchLogs.getSubmodule())
                .field("thread", elasticSearchLogs.getThread())
                .field("operation", elasticSearchLogs.getOperation())
                .field("sessionId", elasticSearchLogs.getSessionId())
                .field("userLogin", elasticSearchLogs.getUserLogin())
                .field("userName", elasticSearchLogs.getUserName())
                .field("office", elasticSearchLogs.getOffice())
                .field("location", elasticSearchLogs.getLocation())
                .field("ip", elasticSearchLogs.getIp())
                .field("device", elasticSearchLogs.getDevice())
            .endObject();
            IndexRequest indexRequest = new IndexRequest("portal-logs-" + date,
                    "logs_info").source(builder);
            client.index(indexRequest);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return GenericResponse.success(null, CODE_200);

    }
```

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 26, 2018, 10:21am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/7 "2018-01-26T10:21:01Z")

</div>

Ok, I think the problem is that in your mapping your type is named `ENTRY` and in your code you're using `logs_info`. Try changing `ENTRY` to `logs_info` in your mapping, recreate your index and try again.

---

<div class="post-metadata">

**Author:** ![Nikita\_Krasnov](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nikita\_Krasnov](https://discuss.elastic.co/u/Nikita_Krasnov)\
**Post date:** [January 26, 2018, 11:27am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/8 "2018-01-26T11:27:12Z")

</div>

`DELETE /_all` helps  
Thanks

---

<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:** [February 23, 2018, 11:27am UTC](https://discuss.elastic.co/t/issue-with-saving-an-object-to-es/117179/9 "2018-02-23T11:27:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
