0

I' m using Elasticsearch 2.3 version with NodeJs 14. I was trying to assign string version of geo_point such as '41.00445520431176,28.976772329847574' instead of { "lat": 41.12, "lon": -71.34 } an error thrown.

Here is the error from Nodejs

StatusCodeError: [mapper_parsing_exception] failed to parse
  at respond (/usr/src/app/node_modules/elasticsearch/src/lib/transport.js:349:15)
  at checkRespForFailure (/usr/src/app/node_modules/elasticsearch/src/lib/transport.js:306:7)
  at HttpConnector.<anonymous> (/usr/src/app/node_modules/elasticsearch/src/lib/connectors/http.js:173:7)
  at IncomingMessage.wrapper (/usr/src/app/node_modules/lodash/lodash.js:4991:19)
  at IncomingMessage.emit (events.js:412:35)
  at IncomingMessage.emit (domain.js:537:15)
  at endReadableNT (internal/streams/readable.js:1334:12)
  at processTicksAndRejections (internal/process/task_queues.js:82:21) {
status: 400,
displayName: 'BadRequest',
path: '/users/_doc',
query: { type: 'user' },
body: {
  error: {
    root_cause: [Array],
    type: 'mapper_parsing_exception',
    reason: 'failed to parse',
    caused_by: [Object]
  },
  status: 400
},
statusCode: 400,
response: '{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"illegal_state_exception","reason":"Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.geo.BaseGeoPointFieldMapper$GeoPointFieldType on field location"}},"status":400}',
toString: [Function (anonymous)],
toJSON: [Function (anonymous)]

Here is the error from Elasticsearch 2.3 which is running in docker

 [2021-10-19 09:29:04,326][DEBUG][action.index             ] [Ghost Dancer] failed to execute [index {[users][_doc][AXyX4gRD7BhLOaBJFlNV], source[{"company_title":"eren-company","country":{"country_code":"tr","country_name":"eren-test","id":225},"createdAt":"2017-11-13T11:19:21+00:00","experience_level":"0","experience_month":0,"experiences":{},"first_name":"eren-test","id":1,"last_name":"eren-lastname","location":"41.00445520431176,28.976772329847574","user_type":"created.user_type"}]}] on [[users][3]]
 MapperParsingException[failed to parse]; nested: IllegalStateException[Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.geo.BaseGeoPointFieldMapper$GeoPointFieldType on field location];
        at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:154)
        at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:309)
        at org.elasticsearch.index.shard.IndexShard.prepareCreate(IndexShard.java:529)
        at org.elasticsearch.index.shard.IndexShard.prepareCreateOnPrimary(IndexShard.java:506)
        at org.elasticsearch.action.index.TransportIndexAction.prepareIndexOperationOnPrimary(TransportIndexAction.java:215)
        at org.elasticsearch.action.index.TransportIndexAction.executeIndexRequestOnPrimary(TransportIndexAction.java:224)
        at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:158)
        at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:66)
        at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryPhase.doRun(TransportReplicationAction.java:639)
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
        at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:279)
        at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:271)
        at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75)
        at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376)
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
 Caused by: java.lang.IllegalStateException: Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.geo.BaseGeoPointFieldMapper$GeoPointFieldType on field location
        at org.elasticsearch.index.mapper.FieldMapper.updateFieldType(FieldMapper.java:397)
        at org.elasticsearch.index.mapper.FieldMapper.updateFieldType(FieldMapper.java:53)
        at org.elasticsearch.index.mapper.DocumentParser.parseDynamicValue(DocumentParser.java:622)
        at org.elasticsearch.index.mapper.DocumentParser.parseValue(DocumentParser.java:442)
        at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:262)
        at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:122)
        ... 17 more

And finally here is the mapping from ElasticSearch.

{
    "users": {
        "mappings": {
            "user": {
                "_meta": {
                    "model": "AppBundle\\Entity\\User"
                },
                "properties": {
                    "company_title": {
                        "type": "string",
                        "boost": 5,
                        "analyzer": "turkishIcu"
                    },
                    "country": {
                        "properties": {
                            "country_code": {
                                "type": "string"
                            },
                            "country_name": {
                                "type": "string"
                            },
                            "id": {
                                "type": "integer"
                            }
                        }
                    },
                    "createdAt": {
                        "type": "date",
                        "format": "strict_date_optional_time||epoch_millis"
                    },
                    "experience_level": {
                        "type": "string",
                        "index": "not_analyzed"
                    },
                    "experience_month": {
                        "type": "integer"
                    },
                    "experiences": {
                        "properties": {
                            "company_name": {
                                "type": "string",
                                "boost": 5,
                                "analyzer": "turkishIcu"
                            },
                            "position": {
                                "type": "string",
                                "boost": 5
                            }
                        }
                    },
                    "first_name": {
                        "type": "string",
                        "boost": 10,
                        "analyzer": "turkishIcu"
                    },
                    "id": {
                        "type": "integer",
                        "boost": 0,
                        "norms": {
                            "enabled": true
                        }
                    },
                    "last_name": {
                        "type": "string",
                        "boost": 10,
                        "analyzer": "turkishIcu"
                    },
                    "location": {
                        "type": "geo_point"
                    },
                    "user_type": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Besides all of the above; When I try to pass { "lat": 41.12, "lon": -71.34 } I get the error below.

 StatusCodeError: [invalid_type_name_exception] Document mapping type name can't start with '_'
     at respond (/usr/src/app/node_modules/elasticsearch/src/lib/transport.js:349:15)
     at checkRespForFailure (/usr/src/app/node_modules/elasticsearch/src/lib/transport.js:306:7)
     at HttpConnector.<anonymous> (/usr/src/app/node_modules/elasticsearch/src/lib/connectors/http.js:173:7)
     at IncomingMessage.wrapper (/usr/src/app/node_modules/lodash/lodash.js:4991:19)
     at IncomingMessage.emit (events.js:412:35)
     at IncomingMessage.emit (domain.js:537:15)
     at endReadableNT (internal/streams/readable.js:1334:12)
     at processTicksAndRejections (internal/process/task_queues.js:82:21) {
   status: 400,
   displayName: 'BadRequest',
   path: '/users/_doc',
   query: { type: 'user' },
   body: {
     error: {
       root_cause: [Array],
       type: 'invalid_type_name_exception',
       reason: "Document mapping type name can't start with '_'"
     },
     status: 400
   },
   statusCode: 400,
   response: `{"error":{"root_cause":[{"type":"invalid_type_name_exception","reason":"Document mapping type name can't start with '_'"}],"type":"invalid_type_name_exception","reason":"Document mapping type name can't start with '_'"},"status":400}`,
   toString: [Function (anonymous)],
   toJSON: [Function (anonymous)]
 }

As I said before;

Thank you for your help.

Sincerely Eren;

Eren Yatkin
  • 186
  • 2
  • 9
  • seems like _doc is deprecated https://stackoverflow.com/questions/35747862/what-does-doc-represents-in-elasticsearch – Ting Lee Oct 19 '21 at 09:59
  • @TingLee Yes I noticed that. But I did not add `_doc` to the query. Package does itself. I tried to switch `@elastic/elasticsearch` but due to old version of elasticsearch, the new package does not recognize the elasticsearch 2.3 instance. Therefore I need to use old package. – Eren Yatkin Oct 19 '21 at 10:22
  • I realized that `type` parameter is not added to the url. I guess package is broken at this point. – Eren Yatkin Oct 19 '21 at 11:11
  • @TingLee you can check my answer – Eren Yatkin Oct 19 '21 at 12:10

1 Answers1

0

I solved the problem. The problem was occurring because of the apiVersion switching to the proper version fixed the issue.

TL;DR;

import { Client } from 'elasticsearch';
this.client = new Client({
   host: configService.get<string>('ELASTICSEARCH_HOST'),
   apiVersion: '5.6',
});

I did some research in the package itself and found out that if you did not specify the apiVersion it automatically imports master api and master api formats the url like below, which is wrong.

  urls: [
    {
      fmt: '/<%=index%>/_doc/<%=id%>',
      req: {
        index: {
          type: 'string'
        },
        id: {
          type: 'string'
        }
      }
    },
    {
      fmt: '/<%=index%>/_doc',
      req: {
        index: {
          type: 'string'
        }
      }
    }
  ]

The whole _doc issues come from this formatting, it does not care the mapping name. I think this is a bug. Then I checked the other apis and they were like below;

  urls: [
    {
      fmt: '/<%=index%>/<%=type%>/<%=id%>',
      req: {
        index: {
          type: 'string'
        },
        id: {
          type: 'string'
        }
      }
    },
    {
      fmt: '/<%=index%>/<%=type%>',
      req: {
        index: {
          type: 'string'
        }
      }
    }
  ]

They include the mapping name which was called type. Then I specify the apiVersion for the Client problem fixed right away.

Eren Yatkin
  • 186
  • 2
  • 9