无法在弹性搜索中创建映射

时间:2019-10-25 10:38:47

标签: ubuntu elasticsearch

我正在尝试第一次运行elasticsearch。 http://localhost:9200返回正确的响应。现在,我试图通过邮递员使用以下文件创建自己的映射:

[POST]本地主机:9200 /人

set key out horiz bot center

但是每当我发布它时,我都会得到以下信息

{
  "mappings" : {
    "person":{
      "properties": {
        "personid":{
          "type": "integer"
        },
        "name":{
          "type": "string"
        },
        "email":{
          "type": "string"
        }
      }
    }
  }
}

我在这里做什么错了?

2 个答案:

答案 0 :(得分:2)

  

要在弹性搜索中添加映射,请始终使用PUT方法

Python 2.7
Input:
json.loads('{"a":"AC","b":"ac","name":"Upgrade","status":"active","dateCreated":"Mon, 22 Aug 2011 20:58:45 +0000","dateUpdated":"Fri, 12 Jul 2011 21:52:26 +0000","token":"bar","type":"Full"}')

Response
{u'a': u'AC', u'status': u'active', u'b': u'ac', u'name': u'Upgrade', u'dateCreated': u'Mon, 22 Aug 2011 20:58:45 +0000', u'token': u'bar', u'dateUpdated': u'Fri, 12 Jul 2011 21:52:26 +0000', u'type': u'Full'}

Python 3
Input:
json.loads(b'{"a":"AC","b":"ac","name":"Upgrade","status":"active","dateCreated":"Mon, 22 Aug 2011 20:58:45 +0000","dateUpdated":"Fri, 12 Jul 2011 21:52:26 +0000","token":"bar","type":"Full"}')

Response:
{'a': 'AC', 'b': 'ac', 'name': 'Upgrade', 'status': 'active', 'dateCreated': 'Mon, 22 Aug 2011 20:58:45 +0000', 'dateUpdated': 'Fri, 12 Jul 2011 21:52:26 +0000', 'token': 'bar', 'type': 'Full'}

答案 1 :(得分:1)

映射

put  localhost:9200/persons  --->  change post to put
{

  "mappings" : {                ----> remove person
      "properties": {
        "personid":{
          "type": "integer"
        },
        "name":{
          "type": "text"       ---> change string to text 
        },
        "email":{
          "type": "text"
        }
      }
    }
  }

如果您打算将personid和其他字段作为person的子字段并使用person.personid进行访问,请在下面使用

{
  "mappings": {
    "properties": {
      "person": {
        "type": "object",
        "properties": {
          "personid": {
            "type": "integer"
          },
          "name": {
            "type": "text"
          },
          "email": {
            "type": "text"
          }
        }
      }
    }
  }
}