use prefix from ES docs
This commit is contained in:
parent
119e51912e
commit
e2441ea3e7
1 changed files with 24 additions and 11 deletions
|
@ -28,7 +28,8 @@ class SearchIndex:
|
||||||
return
|
return
|
||||||
await self.client.indices.create(
|
await self.client.indices.create(
|
||||||
self.index,
|
self.index,
|
||||||
{"settings":
|
{
|
||||||
|
"settings":
|
||||||
{"analysis":
|
{"analysis":
|
||||||
{"analyzer": {
|
{"analyzer": {
|
||||||
"default": {"tokenizer": "whitespace", "filter": ["lowercase", "porter_stem"]}}},
|
"default": {"tokenizer": "whitespace", "filter": ["lowercase", "porter_stem"]}}},
|
||||||
|
@ -36,7 +37,19 @@ class SearchIndex:
|
||||||
{"refresh_interval": -1,
|
{"refresh_interval": -1,
|
||||||
"number_of_shards": 1}
|
"number_of_shards": 1}
|
||||||
},
|
},
|
||||||
|
"mappings": {
|
||||||
|
"properties": {
|
||||||
|
"claim_id": {
|
||||||
|
"type": "text",
|
||||||
|
"index_prefixes": {
|
||||||
|
"min_chars": 1,
|
||||||
|
"max_chars": 10
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"height": {"type": "integer"},
|
||||||
|
"claim_type": {"type": "byte"},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -219,7 +232,7 @@ FIELDS = ['is_controlling', 'last_take_over_height', 'claim_id', 'claim_name', '
|
||||||
'trending_group', 'trending_mixed', 'trending_local', 'trending_global', 'channel_id', 'tx_id', 'tx_nout',
|
'trending_group', 'trending_mixed', 'trending_local', 'trending_global', 'channel_id', 'tx_id', 'tx_nout',
|
||||||
'signature', 'signature_digest', 'public_key_bytes', 'public_key_hash', 'public_key_id', '_id', 'tags',
|
'signature', 'signature_digest', 'public_key_bytes', 'public_key_hash', 'public_key_id', '_id', 'tags',
|
||||||
'reposted_claim_id']
|
'reposted_claim_id']
|
||||||
TEXT_FIELDS = ['author', 'canonical_url', 'channel_id', 'claim_id', 'claim_name', 'description',
|
TEXT_FIELDS = ['author', 'canonical_url', 'channel_id', 'claim_name', 'description',
|
||||||
'media_type', 'normalized', 'public_key_bytes', 'public_key_hash', 'short_url', 'signature',
|
'media_type', 'normalized', 'public_key_bytes', 'public_key_hash', 'short_url', 'signature',
|
||||||
'signature_digest', 'stream_type', 'title', 'tx_id', 'fee_currency', 'reposted_claim_id', 'tags']
|
'signature_digest', 'stream_type', 'title', 'tx_id', 'fee_currency', 'reposted_claim_id', 'tags']
|
||||||
RANGE_FIELDS = ['height', 'fee_amount', 'duration', 'reposted', 'release_time']
|
RANGE_FIELDS = ['height', 'fee_amount', 'duration', 'reposted', 'release_time']
|
||||||
|
@ -266,7 +279,7 @@ def expand_query(**kwargs):
|
||||||
key += '.keyword'
|
key += '.keyword'
|
||||||
ops = {'<=': 'lte', '>=': 'gte', '<': 'lt', '>': 'gt'}
|
ops = {'<=': 'lte', '>=': 'gte', '<': 'lt', '>': 'gt'}
|
||||||
if partial_id:
|
if partial_id:
|
||||||
query['must'].append({"prefix": {"claim_id.keyword": value}})
|
query['must'].append({"prefix": {"claim_id": value}})
|
||||||
elif key in RANGE_FIELDS and isinstance(value, str) and value[0] in ops:
|
elif key in RANGE_FIELDS and isinstance(value, str) and value[0] in ops:
|
||||||
operator_length = 2 if value[:2] in ops else 1
|
operator_length = 2 if value[:2] in ops else 1
|
||||||
operator, value = value[:operator_length], value[operator_length:]
|
operator, value = value[:operator_length], value[operator_length:]
|
||||||
|
|
Loading…
Reference in a new issue