Issue with saving an object to ES


(Nikita Krasnov) #1

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?


(Val Crettaz) #2

Can you show what you get when running this command?

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

(Nikita Krasnov) #3
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

(Nikita Krasnov) #4

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.


(Val Crettaz) #5

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


(Nikita Krasnov) #6

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);

    }

(Val Crettaz) #7

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.


(Nikita Krasnov) #8

DELETE /_all helps
Thanks


(system) #9

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