我将此数据存储在此let name = "TSC-Body.043" // App fails with this "name" definition
// let name = "TSC-Body-043" // App works with this "name" definition
var test = [String:Any]()
if test[name] == nil {
test[name] = UIColor.black
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print("Never gets called with a period in keys")
}
格式的Elasticsearch
中:
json
现在我编写了这段代码,当传递{
"qna": [
{
"qid": "1",
"question": [
"How to use the tool"
],
"answer": "Create and administer your questions Content Designer UI.",
"votes": "0"
},
{
"qid": "2",
"question": [
"How can I include attachements"
],
"answer": "Add an image attachment to the item using the Content Designer.",
"votes": "0"
}
]
}
字符串时,我可以从Elasticsearch获取question
:
answer
您可以看到from elasticsearch import Elasticsearch
def search_es(question,index_name):
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
data = {
"query": {
"function_score":{
"query":{
"match": {
'question': question
}
},
"field_value_factor":{
"field":"votes",
"modifier":"log2p"
}
}
}
}
response = es.search(index=str(index_name).lower(), body=data)
for items in response['hits']['hits']:
score = items['_score']
answer = source['a']
score_answer.append([score,answer])
score_answer.sort(key=lambda x: int(x[0]), reverse=True)
# SELECT ONE ANSWER - TOP SCORED ANSWER
print(score_answer[0][1])
# CODE TO INCREASE VOTE OF THE SELECTED ANSWER
increase_vote(score_answer[0][1])
def increase_vote(answer):
# IMPLEMENT CODE HERE
提取并选择得分最高的search_es()
字段。 现在我要做的是实现一个功能,该功能将更新与所选answer
相关联的votes
字段并将其增加1 。我环顾四周,找到了与answer
等文档partial update
相关的帖子,但我无法找到如何更新字段的方法,如我的方案所述?