class TestData(unittest.TestCase): def setUp(self): client = OpensearchClientFactory.create_client("hangzhou", "external", "XVqTa2Rl5fGpml7c", "ZRXQN8Azm15Z7bWKgD0zVzS0OJR6A9") self.data_mgr = DataMgr(client) def test_upload_P1(self): with codecs.open("../files/test4_main.txt") as ifh: json_str = ifh.read() resp = self.data_mgr.upload("test5", "main", json_str) self.assertTrue(resp.success()) def test_upload_P2(self): json_str = """ [ { "cmd": "add", "timestamp": 1401342874777, "fields": { "id": "1", "title": "This is the title", "body": "This is the body" } }, { "cmd": "update", "timestamp": 1401342874778, "fields": { "id": "2", "title": "This is the new title" } }, { "cmd": "delete", "fields": { "id": "3" } } ] """ resp = self.data_mgr.upload("F7xBML", "main", json_str) self.assertTrue(resp.success())
"cmd": "update", "timestamp": 1401342874778, "fields": { "id": "2", "title": "This is the new title" } }, { "cmd": "delete", "fields": { "id": "3" } } ] """ resp = data_mgr.upload(app_name, "main", json_str) # a little like create app's result: if resp.success(): print("upload date to %s success" % app_name) print(resp.result) # search is NOT thread safe, please create a instance for each query search = Search(client) search.query("title").index_name(app_name) results = search.results() # search result is also like common result, you could do anything you want when get json object if results.success(): print("query success")