Query
常見名詞
Index建立、文章新增
#連線server
es=Elasticsearch([{'host': 'localhost', 'port': 9200}])
#如果需要身分驗證
es=Elasticsearch(['ip&port'],http_auth=('username','password'))
#建立index
#若連線狀態是ignore則回傳錯誤訊息
#建立時可在body加上表格欄位設定(table_format),也就是mapping設定
#其中article即doc_type
table_format={
"mappings":{
"article":{
"properties":{
"title":{
"type":"string",
"index":"not_analyzed"
},
"content" : {
"type":"string",
"index":"not_analyzed"
}
}
}
}
}
res=es.indices.create(index=index_name, ignore=[400,409,404], body=table_format)
#判斷index是否存在,會回傳boolean
res=es.indices.exists(index='index_name')
#新增資料至doc_type中
#id可以是任意字串
# index :若已存在則覆蓋
# create:若已存在則error
res=es.create(index='index_name', doc_type='article', id='aid', body=data)
res=es.index(index='index_name', doc_type='article', id='aid', body=data)mapping 映射
score 相關性
查詢語法
match
match_phrase
term
terms
aggregations
組合查詢
Range
巢狀判斷式
Last updated