Alt satır sınırlarını koruyarak ve isteğe bağlı olarak eşleşen alt satırları döndürerek Nested alanındaki verileri eşleştirmek için Python için Tablestore SDK'yı kullanın.
Ön koşullar
Python için Tablestore SDK öğesini yükleyin ve bir istemci başlatın.
Açıklama
İç içe sorgu, Nested alanındaki alt satırları sorgular. Her alt satır, kendi alanları arasındaki ilişkileri korur. Bir alt alana doğrudan sorgu uygulayamazsınız; alt sorguyu NestedQuery ile sarmalamanız gerekir. path parametresi Nested alanının yolunu belirtir ve alt sorgudaki alanlar tam yollar kullanmalıdır. Alt sorgu herhangi bir Query türü olabilir. Aynı alt satırın birden çok koşulu karşılaması gerekiyorsa, koşulları tek bir NestedQuery içindeki alt sorgu olarak içeren bir BoolQuery kullanın. Farklı alt satırlar farklı koşulları karşılayabiliyorsa, her koşul için birer NestedQuery oluşturun ve bunları dış bir BoolQuery ile birleştirin.
NestedQuery(path, query, score_mode=ScoreMode.NONE, inner_hits=None, weight=None)
Aşağıdaki örnek, items Nested alanının aynı alt satırında items.name değerinin alice olduğu ve items.age değerinin 40'tan küçük olduğu satırları sorgular.
child_query = BoolQuery(
must_queries=[
TermQuery("items.name", "alice"),
RangeQuery("items.age", range_to=40),
]
)
query = NestedQuery("items", child_query)
search_query = SearchQuery(
query,
limit=10,
get_total_count=True,
)
response = client.search(
"example_table",
"example_index",
search_query,
ColumnsToGet(return_type=ColumnReturnType.ALL),
)
print(response.total_count)
for row in response.rows:
print(row)
Parametreler
Arama isteği
search yöntemi aşağıdaki parametreleri içerir.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sorgu yapılandırması
search_query, SearchQuery türündedir ve aşağıdaki parametreleri içerir.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sorgu koşulu
search_query.query, NestedQuery türündedir ve aşağıdaki parametreleri içerir.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Eşleşen alt satırlar
search_query.query.inner_hits, InnerHits türündedir ve aşağıdaki parametreleri içerir.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülen sütunlar
columns_to_get, ColumnsToGet türündedir ve aşağıdaki parametreleri içerir.
|
|
|
|
|
|
|
|
|
|
|
|
Yanıt
search yöntemi SearchResponse döndürür. Aşağıdaki tabloda temel alanlar açıklanmaktadır.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tuple uyumlu yanıt
Python için Tablestore SDK 5.2.0 sürümünden itibaren arama API'leri tuple yerine yanıt nesneleri döndürür. 5.1.0 ve önceki sürümler doğrudan tuple döndürür. 5.2.1 ve sonraki sürümlerde, önceki sürümlerle uyumlu bir tuple elde etmek için SearchResponse.v1_response() yöntemini çağırabilirsiniz. Yeni kodlarda, yanıt alanları genişletildiğinde paket açma hatalarını önlemek için SearchResponse özniteliklerine doğrudan erişin.
(
rows,
next_token,
total_count,
is_all_succeed,
agg_results,
group_by_results,
search_hits,
) = response.v1_response()
Örnekler
Eşleşen alt satırları ve vurgulamaları döndürme
Aşağıdaki örnek, items.name değerinin alice olduğu iç içe geçmiş alt satırları sorgular ve eşleşen alt satırlarla vurgulanan parçaları döndürür. Vurgulama sonuçları search_hits[].search_inner_hits[].search_hits[].highlight_result konumunda kullanılabilir.
highlight = Highlight([HighlightParameter("items.name")])
inner_hits = InnerHits(
sort=None,
offset=0,
limit=10,
highlight=highlight,
)
query = NestedQuery(
"items",
TermQuery("items.name", "alice"),
inner_hits=inner_hits,
)
response = client.search(
"example_table",
"example_index",
SearchQuery(query, limit=10),
)
for search_hit in response.search_hits:
for inner_hit in search_hit.search_inner_hits:
for child_hit in inner_hit.search_hits:
print(child_hit.row)
print(child_hit.highlight_result.highlight_fields)