Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PutMapping api url is incorrect #102

Closed
bleupen opened this issue May 14, 2014 · 13 comments
Closed

PutMapping api url is incorrect #102

bleupen opened this issue May 14, 2014 · 13 comments

Comments

@bleupen
Copy link

bleupen commented May 14, 2014

it's currently "/<%=index%>/_mapping/<%=type%>"

should this be changed to "/<%=index%>/<%=type%>/_mapping"?

@spalger
Copy link
Contributor

spalger commented May 19, 2014

@bleupen, it looks like you are expecting the 0.90 API. You should try setting the apiVerson config param.

@spalger spalger closed this as completed May 19, 2014
@bleupen
Copy link
Author

bleupen commented May 19, 2014

this test fails for me:

    it('should put a mapping', function (done) {
        var client = new es.Client({
            host: 'localhost:9200',
            log: 'trace',
            apiVersion: '1.0'
        });

        client.indices.putMapping({
            index: 'testIndex',
            type: 'testType',
            body: {
                'testType': {
                    properties: {
                        message: {type: 'string', store: true}
                    }
                }
            }
        }).then(function (response) {
            console.log(response);
            done();
        }).done();
    });

I get:

Elasticsearch TRACE: 2014-05-19T17:19:13Z
  -> PUT http://localhost:9200/testIndex/_mapping/testType
  {
    "testType": {
      "properties": {
        "message": {
          "type": "string",
          "store": true
        }
      }
    }
  }
  <- 400
  {
    "error": "InvalidTypeNameException[mapping type name [_mapping] can\u0027t start with \u0027_\u0027]",
    "status": 400
  }

Hopefully I'm just doing something dumb.

@spalger
Copy link
Contributor

spalger commented May 19, 2014

Take a look at the error, it says "Invalid index name [testIndex], must be lowercase"

@bleupen
Copy link
Author

bleupen commented May 19, 2014

sorry i was tinkering with my source to make it easy to paste. I updated the comment with the actual error message.

@bleupen
Copy link
Author

bleupen commented May 19, 2014

(my index name is now lower case)

@bleupen
Copy link
Author

bleupen commented May 19, 2014

here you go. full test and error message:

    it('should put a mapping', function (done) {
        var client = new es.Client({
            host: 'localhost:9200',
            log: 'trace',
            apiVersion: '1.1'
        });

        client.indices.putMapping({
            index: 'myindex',
            type: 'mytype',
            body: {
                'mytype': {
                    properties: {
                        message: {type: 'string', store: true}
                    }
                }
            }
        }).then(function (response) {
            console.log(response);
            done();
        }).done();
    });
Elasticsearch TRACE: 2014-05-19T17:31:30Z
  -> PUT http://localhost:9200/myindex/_mapping/mytype
  {
    "mytype": {
      "properties": {
        "message": {
          "type": "string",
          "store": true
        }
      }
    }
  }
  <- 400
  {
    "error": "InvalidTypeNameException[mapping type name [_mapping] can\u0027t start with \u0027_\u0027]",
    "status": 400
  }

@spalger spalger reopened this May 19, 2014
@bleupen
Copy link
Author

bleupen commented May 19, 2014

yes, the index must exist, but the test passes with the index/type/_mapping syntax and fails with the out of the box defaults.

@bleupen
Copy link
Author

bleupen commented May 19, 2014

Your work-around also works, thanks!

@spalger
Copy link
Contributor

spalger commented May 19, 2014

Something else is going on here, it works fine for me. If more people report an issue I'll look into it but for now, I'm stumped.

# TRACE: 2014-05-19T17:50:39Z
# http://localhost:9400
curl 'http://localhost:9200/test_index?pretty=true' -XPOST
# -> 200
# {"acknowledged":true}

# INFO: 2014-05-19T17:50:39Z
# Request complete

# DEBUG: 2014-05-19T17:50:39Z
# starting request { method: 'PUT',
#   path: '/test_index/_mapping/test_type',
#   body: { test_type: { properties: [Object] } },
#   query: {} }
# 

# TRACE: 2014-05-19T17:50:39Z
# http://localhost:9400
curl 'http://localhost:9200/test_index/_mapping/test_type?pretty=true' -XPUT -d '{
  "test_type": {
    "properties": {
      "text1": {
        "type": "string",
        "analyzer": "whitespace"
      },
      "text2": {
        "type": "string",
        "analyzer": "whitespace"
      }
    }
  }
}'
# -> 200
# {"acknowledged":true}

@spalger spalger closed this as completed May 19, 2014
@bleupen
Copy link
Author

bleupen commented May 19, 2014

ok i am an idiot. i was positive i had upgraded my elasticsearch on my dev machine but apparently i had not. i am running 0.9 and changing my test to require api version 0.9 fixes the issue. sorry to have wasted your time.

@spalger
Copy link
Contributor

spalger commented May 19, 2014

haha, oh @bleupen :P
No big. it happens.

@Amberlamps
Copy link

Hey guys. I am using ElasticSearch 1.2.1 on Windows. I wanted to create an index and set the mapping after creation. I followed the API documentation and did the following:

client.create({ index: 'blog', type: 'post' }, function(err, body, code) {
    client.indices.putMapping({ index: 'blog', type: 'post', body: { title: { type: 'string' }} }, function(err, body, code) {
        if (err) throw new Error(err);
    });
});

That actually throws the error:

Error: MapperParsingException[Root type mapping not empty after parsing! Remaining fields: [title : {type=string}]]

So I dug into the code and replaced the line:

fmt: '/<%=index%>/_mapping/<%=type%>',

in /src/lib/apis/1_2.js under api.indices.prototype.putMapping with:

fmt: '/<%=index%>',

At least there was no error no more, but also the mapping was not applied. When I realized that this is basically the url for creating an index, I altered my code to this:

var params = {
  index: 'blog',
  type: 'post',
  body: {
    'mappings': {
      'post': {
        'properties': {
          'title': {
            type: 'string'
          }
        }
      }
    }
  }
};
client.indices.create(params, function(err, body, code) {
  console.log('index created');
});

That actually created my index and set the mapping at the same time. I think my point here is that I never managed to run the putMapping() function successfully.

@spalger
Copy link
Contributor

spalger commented Jul 5, 2014

@Amberlamps Check out the body from the first example here: http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-put-mapping.html#indices-put-mapping

The mapping needs to be wrapped in the type name, "properties", and then the hash of mappings. Your example modified:

client.create({ index: 'blog', type: 'post' }, function(err, body, code) {
    var body = { post: { properties: { title: { type: 'string' }}}};
    client.indices.putMapping({ index: 'blog', type: 'post', body: body }, function(err, body, code) {
        if (err) throw new Error(err);
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants