我已使用以下索引設定將資料索引到 ElasticSearch 中:
KNN_INDEX = {
"settings": {
"index.knn": True,
"index.knn.space_type": "cosinesimil",
"index.mapping.total_fields.limit": 10000,
"analysis": {
"analyzer": {
"default": {
"type": "standard",
"stopwords": "_english_"
}
}
}
},
"mappings": {
"dynamic_templates": [
{
"sentence_vector_template": {
"match": "sent_vec*",
"mapping": {
"type": "knn_vector",
"dimension": 384,
"store": True
}
}
},
{
"sentence_template": {
"match": "sentence*",
"mapping": {
"type": "text",
"store": True
}
}
}
],
'properties': {
"metadata": {
"type": "object"
}
}
}
}
以下是我在 ElasticSearch 中編制索引的幾個示例檔案:
{
# DOC 1
"sentence_0": "Machine learning for aquatic plastic litter detection, classification and quantification (APLASTIC-Q)Large quantities of mismanaged plastic waste are polluting and threatening the health of the blue planet."
"sentence_1": "As such, vast amounts of this plastic waste found in the oceans originates from land."
"sentence_2": "It finds its way to the open ocean through rivers, waterways and estuarine systems."
},
{
# DOC 2
"sentence_0": "What predicts persistent early conduct problems?"
"sentence_1": "Evidence from the Growing Up in Scotland cohortBackground There is a strong case for early identification of factors predicting life-course-persistent conduct disorder."
"sentence_2": "The authors aimed to identify factors associated with repeated parental reports of preschool conduct problems."
"sentence_3": "Method Nested caseecontrol study of Scottish children who had behavioural data reported by parents at 3, 4 and 5 years."
"sentence_4": "Results 79 children had abnormal conduct scores at all three time points ('persistent conduct problems') and 434 at one or two points ('inconsistent conduct problems')."
}
每個索引檔案可以有不同數量的句子。對于查詢,我想搜索所有檔案中的所有句子。我可以使用以下查詢在所有檔案中搜索特定的“句號”:
query_body = {
"query": {
"match": {
"sentence_0": "persistent"
}
}
}
result = client.search(index=INDEX_NAME, body=query_body)
print(result)
但我正在尋找的是如下內容:
query_body = {
"query": {
"match": {
"sentence_*": "persistent"
}
}
}
result = client.search(index=INDEX_NAME, body=query_body)
print(result)
上面的查詢雖然不起作用。是否可以執行這樣的查詢搜索?謝謝。
uj5u.com熱心網友回復:
使用query_string它支持欄位名稱中的正則運算式
{
"query": {
"query_string": {
"fields": ["sentence*"],
"query": "persistent"
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/523558.html
標籤:弹性搜索开放搜索
