Hi all, I am trying to ingest json file in Elasticsearch using python , but index is not getting created

Code is running , I'm not getting any error . But at a same time index is not created .

Here is my code.

import sys
import json
from pprint import pprint
from Elasticsearch import Elasticsearch
es = Elasticsearch(
['localhost'],
port=9200

)

es = Elasticsearch(host = "localhost", port = 9200)

MyFile= open(r"D:/elastic_php/test.json",'r').read()
ClearData = MyFile.splitlines(True)
i=0
json_str=""
docs ={}
for line in ClearData:
line = ''.join(line.split())
if line != "},":
json_str = json_str+line
else:
docs[i]=json_str+"}"
json_str=""
print(docs[i])
es.index(index='wiki', doc_type='doc', id=i, body=docs[i])
i=i+1

Any solution on this?

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.