[英]python elasticsearch dsl search for field with white space
情況1有效,但情況2無效,這是由於空白。 這是一個已經創建了一段時間並被許多人使用的索引,所以我的搜索存在問題,而不是索引。 也許與令牌生成器或分析器有關,但不確定什么/如何做
情況2由於“舊金山”中的空白而未返回任何數據
情況1
s = Search(using=client, index = "my_index")
s = s.query("nested",
path="party.partyAddress",
query=Q("term", party__partyAddress__city="fremont")
)
print (s.execute)
情況2
s = Search(using=client, index = "my_index")
s = s.query("nested",
path="party.partyAddress",
query=Q("term", party__partyAddress__city="san francisco")
)
s.execute
print (s.execute)
根據要求添加映射
{
u'policiesrel3': {
u'mappings': {
u'data': {
u'properties': {
u'prodTypeCode': {
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'contractAddress': {
u'type': u'nested',
u'properties': {
u'city': {
u'type': u'string',
u'store': True
},
u'addressType': {
u'type': u'string',
u'store': True
},
u'address1': {
u'type': u'string',
u'store': True
},
u'address2': {
u'type': u'string',
u'store': True
},
u'address3': {
u'type': u'string',
u'store': True
},
u'zipCode': {
u'type': u'string',
u'store': True
},
u'pinLatLongLoc': {
u'properties': {
u'location': {
u'type': u'nested'
}
}
},
u'state': {
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
}
}
},
u'agencyCode': {
u'include_in_all': True,
u'type': u'string',
u'store': True
},
u'docType': {
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'policyNumber_suggest': {
u'preserve_separators': True,
u'analyzer': u'simple',
u'payloads': False,
u'max_input_length': 50,
u'preserve_position_increments': True,
u'type': u'completion'
},
u'mdmContractTransactionTimestamp': {
u'type': u'string'
},
u'productCode': {
u'include_in_all': True,
u'type': u'string',
u'store': True
},
u'policyLoadedToEStimeStamp': {
u'type': u'string'
},
u'memType': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'termExpirationDate': {
u'include_in_all': True,
u'index': u'analyzed',
u'type': u'date',
u'store': True,
u'format': u'yyyy/MM/dd'
},
u'policyStatus': {
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'party': {
u'include_in_parent': True,
u'type': u'nested',
u'properties': {
u'maritalStatus': {
u'type': u'string',
u'store': True
},
u'suffix': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'prefix': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'memNum': {
u'type': u'string'
},
u'lastName_suggest': {
u'preserve_separators': True,
u'analyzer': u'simple',
u'payloads': False,
u'max_input_length': 50,
u'preserve_position_increments': True,
u'type': u'completion'
},
u'partyTransactionTimeStamp': {
u'include_in_all': True,
u'type': u'string',
u'store': True
},
u'memDt': {
u'type': u'date',
u'format': u'yyyy/MM/dd HH:mm:ss||yyyy/MM/dd'
},
u'customerStatus': {
u'type': u'string',
u'store': True
},
u'middleName': {
u'type': u'string',
u'store': True
},
u'empInd': {
u'type': u'string',
u'store': True
},
u'roleList': {
u'include_in_parent': True,
u'type': u'nested',
u'properties': {
u'roleEndDate': {
u'type': u'date',
u'format': u'yyyy/MM/dd HH:mm:ss||yyyy/MM/dd'
},
u'partyRoleType': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'sourceId': {
u'include_in_all': True,
u'type': u'string',
u'store': True
},
u'roleStatus': {
u'type': u'string'
},
u'sourceID': {
u'type': u'string'
}
}
},
u'pegaAccount': {
u'type': u'string'
},
u'email': {
u'type': u'string'
},
u'partyAddress': {
u'type': u'nested',
u'properties': {
u'city': {
u'type': u'string',
u'store': True
},
u'addressType': {
u'type': u'string',
u'store': True
},
u'address1': {
u'type': u'string',
u'store': True
},
u'address2': {
u'type': u'string',
u'store': True
},
u'address3': {
u'type': u'string',
u'store': True
},
u'zipCode': {
u'type': u'string',
u'store': True
},
u'pinLatLongLoc': {
u'properties': {
u'location': {
u'type': u'geo_point'
}
}
},
u'state': {
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
}
}
},
u'dobYear': {
u'type': u'string',
u'store': True
},
u'registrationId': {
u'type': u'string'
},
u'fullName': {
u'search_analyzer': u'typeahead_search_ngram',
u'index_analyzer': u'typeahead_index_ngram',
u'type': u'string'
},
u'partyIDs': {
u'dynamic': u'false',
u'type': u'nested',
u'properties': {
u'idType': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'details': {
u'type': u'nested',
u'properties': {
u'startDate': {
u'type': u'date',
u'format': u'yyyy/MM/dd'
},
u'endDate': {
u'type': u'date',
u'format': u'yyyy/MM/dd'
},
u'number': {
u'type': u'string',
u'store': True
},
u'sourceValue': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
}
}
}
}
},
u'firstName_suggest': {
u'preserve_separators': True,
u'analyzer': u'simple',
u'payloads': False,
u'max_input_length': 50,
u'preserve_position_increments': True,
u'type': u'completion'
},
u'firstName': {
u'include_in_all': True,
u'fields': {
u'autocomplete': {
u'type': u'string',
u'analyzer': u'simple'
},
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'dob': {
u'type': u'date',
u'store': True,
u'format': u'yyyy/MM/dd'
},
u'gender': {
u'type': u'string',
u'store': True
},
u'mdmId': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'driversLicenseNumber': {
u'type': u'string'
},
u'SSN': {
u'type': u'string'
},
u'phoneList': {
u'type': u'nested',
u'properties': {
u'phoneExtension': {
u'type': u'string',
u'store': True
},
u'phoneFullNumber': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'phoneExchange': {
u'type': u'string',
u'store': True
},
u'phoneNumber': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'phoneType': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'phoneAreaCode': {
u'type': u'string',
u'store': True
}
}
},
u'lastName': {
u'include_in_all': True,
u'fields': {
u'autocomplete': {
u'type': u'string',
u'analyzer': u'simple'
},
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
}
}
},
u'ubiFlag': {
u'index': u'not_analyzed',
u'type': u'string',
u'store': True
},
u'policyType': {
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'policyNumberPartial': {
u'include_in_all': True,
u'fields': {
u'autocomplete': {
u'type': u'string',
u'analyzer': u'simple'
}
},
u'type': u'string',
u'store': True
},
u'sourceSystem': {
u'include_in_all': True,
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'contractTransactionTimeStamp': {
u'include_in_all': True,
u'type': u'string',
u'store': True
},
u'policyInceptionDate': {
u'include_in_all': True,
u'index': u'analyzed',
u'type': u'date',
u'store': True,
u'format': u'yyyy/MM/dd'
},
u'policyNumber': {
u'include_in_all': True,
u'fields': {
u'autocomplete': {
u'search_analyzer': u'typeahead_search_ngram',
u'index_analyzer': u'typeahead_index_ngram',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'termEffectiveDate': {
u'include_in_all': True,
u'index': u'analyzed',
u'type': u'date',
u'store': True,
u'format': u'yyyy/MM/dd'
},
u'riskState': {
u'include_in_all': True,
u'fields': {
u'raw': {
u'index': u'not_analyzed',
u'type': u'string'
}
},
u'type': u'string',
u'store': True
},
u'mdmPartyTransactionTimestamp': {
u'type': u'string'
},
u'agentid': {
u'include_in_all': True,
u'type': u'string',
u'store': True
}
}
}
}
}
}
從映射看來,默認分析器( https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html )用於此字段,這是對字段值進行標記。 您正在搜索term
,它正在搜索確切的術語。 如果使用match
,則應該得到結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.