在opensearch中另存为数组

问题描述 投票:0回答:1

我需要将值保存为数组,

    def push_to_opensearch(data):
       """ just for testing in localhost hosted opensearch"""
       index_name = 'new_index_name'
       url = f"https://localhost:9200/{index_name}/_doc/"
       auth_credentials = HTTPBasicAuth('admin', 'BSOIT2020')
       response = requests.post(url, json=data, auth=auth_credentials, verify=False)
       print(f" response from local opensearch {response.text}")

示例数据

    {
         'id': 693103, 
         'platform': ['PlayStation 4, Cassette Recorder']
    }

目前,OpenSearch 会将其另存为

PlayStation 4, Cassette Recorder
。我想要的是将其另存为
['PlayStation 4', 'Cassette Recorder']

映射看起来像这样

 {
    ......
    "platform": {
       "type": "keyword",
       "ignore_above": 200
     }

  },

如果我将其更改为

   {
     'id': 693103, 
     'platform': ['PlayStation 4', 'Cassette Recorder']
    }

仅保存第一个元素。

有什么想法吗

python opensearch
1个回答
0
投票

正确的格式是

   {
      'id': 693103, 
      'platform': ['PlayStation 4', 'Cassette Recorder']
   }

但是,当使用 Query Workbench 时,它只会显示第一个元素,但使用开发工具查询时,它将显示正确的数据

© www.soinside.com 2019 - 2024. All rights reserved.