[英]python elasticsearch dsl search for field with white space
case 1 works but not case 2 and this is due to the white space. 情况1有效,但情况2无效,这是由于空白。 This is an index that has been created for sometime and used by many folks so is something wrong with my search not with the index.
这是一个已经创建了一段时间并被许多人使用的索引,所以我的搜索存在问题,而不是索引。 Perhaps it has something to do with the tokenizer or analyser but not sure what/how
也许与令牌生成器或分析器有关,但不确定什么/如何做
case 2 returns no data due to the whitespace in "san francisco" 情况2由于“旧金山”中的空白而未返回任何数据
case 1 情况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)
case 2 情况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)
Adding mapping as requested 根据要求添加映射
{
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
}
}
}
}
}
}
From the mapping it seems that the default analyzer ( https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html ) is used for this field, which is tokenizing the field value. 从映射看来,默认分析器( https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html )用于此字段,这是对字段值进行标记。 You are searching with
term
, which is searching for the exact term. 您正在搜索
term
,它正在搜索确切的术语。 If you use match
, you should get results. 如果使用
match
,则应该得到结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.