想要生成如下格式jason文件:
{
"query": {
"bool": {
"should": [
{"term": {
"staticUrl.keyword": "/text2video/videos/sanguo-jilu/sanguo-01/0.mp4"
}},
{"term": {
"staticUrl.keyword": "/text2video/videos/sanguo-jilu/sanguo-01/1.mp4"
}}
]
}
}
}
python代码:
import json
article = {'query': {'bool':{ 'should': []}}}
with open("flist2.video") as f:
for l in f.readlines():
l=l.replace('\n', '')
item={"term": {"staticUrl.keyword": "/text2video/videos/sanguo-jilu/"+l}}
article['query']['bool']['should'].append(item)
data = json.dumps(article, ensure_ascii=False,sort_keys=True, indent=4, separators=(',', ':'))
print(data)