【发布时间】:2016-02-03 04:22:28
【问题描述】:
如何避免多余的单引号
keywords = "van","buren","william","henry","harrison"
当我打印关键字时
打印关键字
输出:
“范”、“布伦”、“威廉”、“亨利”、“哈里森”
很好的控制台窗口
当我在查询中使用相同的变量时
"fields": ["name","contextType"],
"query": {
"bool": {
"must": [
{
"match": { "contextType": "{}".format(querystring)}
},
{
"terms": {
"content": **["%s" % (keywords)]**
}
}
]
}
}
以下是输出
单引号自动添加
{'query': {'bool': {'must': [{'match': {'contextGraph.contextType': 'president'}}, {'terms': {'content': ***['"van","buren","william","henry","harrison"']***
}}]}}}
我的预期输出
{'query': {'bool': {'must': [{'match': {'contextGraph.contextType': 'president'}}, {'terms': {'content': ***["van","buren","william","henry","harrison"]***
}}]}}}
【问题讨论】:
-
你就不能
{'content':keywords[:]}吗? -
感谢@Jason,非常好的技术