我在我正在搜索的圖中有一些條目(例如hello_world, foo_bar_baz),我希望能夠搜索“hello”并回傳 hello_world。
目前,如果我搜索整個字串(即搜索hello_world或foo_bar_baz),我只會得到結果
這似乎是由于 elasticsearch 的標準分析器行為,但我不知道如何用 Neptune 處理這個問題。
with neptune_graph() as g:
my_query = " OR ".join(
f"predicates.{field}.value:({query})" for field in ['names', 'spaces']
)
search_results = (
g.withSideEffect(
"Neptune#fts.endpoint", f"https://{neptuneSearchURL}"
)
.withSideEffect("Neptune#fts.queryType", "query_string")
.withSideEffect("Neptune#fts.sortOrder", "DESC")
.V()
.hasLabel("doc")
.has(
"*",
f"Neptune#fts entity_type:table AND ({my_query})",
)
)
uj5u.com熱心網友回復:
一種方法是使用通配符。
鑒于:
g.addV('search-test').property('name','Hello_World')
v[0ebedfda-a9bd-e320-041a-6e98da9b1379]
假設搜索集成都已經到位,在搜索索引更新后,以下將找到頂點:
g.withSideEffect("Neptune#fts.endpoint",
"https://vpc-neptune-xxx-abc123.us-east-1.es.amazonaws.com").
withSideEffect('Neptune#fts.queryType', 'query_string').
V().
has('name','Neptune#fts hello*').
elementMap().
unfold()
哪個產量
{<T.id: 1>: '0ebedfda-a9bd-e320-041a-6e98da9b1379'}
{<T.label: 4>: 'search-test'}
{'name': 'Hello_World'}
uj5u.com熱心網友回復:
我遇到的問題確實是分析器,但直到現在我才知道如何修復它。
首先在創建 elasticsearch 索引時,您需要設定您想要的設定。
解決方案是使用創建索引
with neptune_search() as es:
es.indices.create(index="my_index", body={/*set custom analyser here*/});
es.index(index="my_index", ... other stuff);
# example of changing the analyser (needs "" around keys and values)
#body={
# settings:{analysis:{analyzer:{default:{
# type: custom,
# tokenizer:"lowercase"
# }}}}
#}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/383823.html
