Elastic App Search 入門


官方文檔地址:https://swiftype.com/documentation/app-search/getting-started

Elastic App Search 架構圖:

它的特點是幫助開發者隨心所欲的為已有的或者正在開發的項目增加功能強大的搜索功能,而且將搜索功能的實施成本降低到無痛點的程度。App Search 可以覆蓋的使用場景如下:
SaaS / web 應用
復雜的電商應用
客戶支持服務站點
Geo 地理搜索
公司官網
內部的搜索
還有更多其他

1.安裝好elasticsearch和kibana,不使用https,不開啟安全,不設置賬號密碼等,分別啟動等
2.配置java環境,詳看這篇文章:https://www.cnblogs.com/sanduzxcvbnm/p/12522735.html
3.在Elasticsearch的安裝根目錄中打開文件config/elasticsearch.yml文件,並添加如下的配置:

action.auto_create_index: ".app-search-*-logs-*,-.app-search-*,+*"

等修改完后,重新啟動Elasticsearch

4.打開App search安裝目錄下的confing/app-search.yml文件,做如下的配置:

allow_es_settings_modification: true
elasticsearch.host: http://192.168.80.10:9200 # 連接es的地址,根據實際情況而定

# Define the exposed URL at which users will reach App Search.定義用戶訪問應用程序搜索的公開URL
app_search.external_url: http://192.168.80.10:3002

# Web application listen_host and listen_port.Web應用程序偵聽主機和偵聽端口
app_search.listen_host: 192.168.80.10
app_search.listen_port: 3002
# app_search連接es的話配置的es的有賬號和密碼,則在初始化app_search的時候會自動給app_search創建賬號密碼

啟動app_search,信息如下:

5.打開瀏覽器,輸入地址http://192.168.80.10:3002,出現的界面如下:

到此為止,App Search 服務器的安裝就完成了。它其實是一個基於 Elasticsearch 的搜索服務平台。

點擊上面的Continue to Dashboard按鈕:

點擊右上角的Skip跳過的話則會進入這個界面:

查看kibana索引管理信息,會看到有好多.app-search的系統索引

6.導入json文件
點擊左上角的"Engines",然后再點擊右上角的"Create an Engines",輸入Engines名稱,然后點擊"Create Engines"

進入到如下界面:

有三種導入數據的方式:
第一種:選擇"Paste JSON",粘貼json數據,然后導入
第二種:選擇"Upload a JSON File",選擇一個json文件,然后導入
第三種:使用API接口導入文件

我這邊采用第二種方式:

7.修改索引的schema
這是因為在默認的情況下,所有的11個字段都被視為text類型。
在完成我們的修改過后,點擊Update Types按鈕。這樣我們的索引將會被重新更新。

8.調節相關度
具有三個關鍵的相關功能:Synonyms(同義詞),Curations(管理)和Relevance Tuning(相關度調整)。
8.1 Synonyms
單擊進入同義詞,然后選擇創建同義詞集並輸入術語:

現在,搜索FF與搜索Final Fantasy的權重相同。

8.2 Curations
單擊“Curations”,然后輸入查詢:“Final Fantasy”。
接下來,通過抓住表格最左側的把手將“Final FantasyVII”文檔拖到“Promoted Documents”部分:

然后單擊“Final Fantasy XIII”文檔上的“Hide Result”按鈕(那個有一條線穿過眼睛的圖標,下圖列表中第三個圖標):

現在,執行“Final Fantasy”或“FF”搜索的任何人都將首先看到“Final Fantasy VII”:

可以升級和隱藏許多文檔。 我們甚至可以對升級后的文檔進行排序,因此我們可以完全控制每個查詢頂部顯示的內容。
8.3 Relevance tuning
單擊邊欄中的“Relevance Tuning”,可以選擇一個字段,可以增加其相關性的權重,在右側可以實時查看調整權重后搜索文檔的排名效果

將滑塊拖動到更高的值,然后單擊“Save”。

9.Reference UI
Reference UI 是提供給用戶使用的搜索界面,它可以是只有一個輸入框,也可以是比較復雜的條件查詢
點擊Reference UI,並做相應的配置。點擊Generate a Preview按鈕:

這樣我們就可以看到如上所示的用戶界面。我們可以嘗試輸入一個關鍵字比如 final fantasy來進行搜索:


馬上看到我們想要的結果了。
還可以點擊上面顯示的filter及sort by,作進一步操作

沒有做任何的開發就有一個非常酷的界面給我們進行搜索了。

10.導出
點擊上面屏幕右上角的Download Zip Package,並保存於一個文件目錄中

解壓這個壓縮包:

可以看到這是一個nodejs的應用程序。使用如下的命令來進行安裝,本機先安裝nodejs:

npm install

一旦安裝完后,我們可以使用如下的命令來進行運行:

npm start

可以看到和之前一樣的界面。

部署到nginx項目中:
然后運行 npm run build 命令,會把nodejs應用打包到一個名為bulid的文件夾中,

npm run build

最后把bulid的文件夾中的所有內容移動到nginx的html目錄下,啟動nginx,就能使再次使用瀏覽器訪問了。

mv -f build/* /usr/share/nginx/html

app-search的安全設置鏈接

https://swiftype.com/documentation/app-search/self-managed/security

Default Configuration File

## ===================== Elastic App Search Configuration =====================
#
# NOTE: Elastic App Search comes with reasonable defaults.
#       Before adjusting the configuration, make sure you understand what you
#       are trying to accomplish and the consequences.
#
# NOTE: For passwords, the use of environment variables is encouraged
#       to keep values from being written to disk, e.g.
#       elasticsearch.password: ${ELASTICSEARCH_PASSWORD:changeme}
#
# ------------------------------- Elasticsearch -------------------------------
#
# App Search needs one-time permission to alter Elasticsearch settings.
# Ensure the Elasticsearch settings are correct, then set the following to
# true.
# Or, adjust Elasticsearch's config/elasticsearch.yml instead.
# See README.md for more details.
#
#allow_es_settings_modification: false
#
# Elasticsearch full cluster URL:
#
#elasticsearch.host: http://127.0.0.1:9200
#
# Elasticsearch credentials:
#
#elasticsearch.username: elastic
#elasticsearch.password: changeme
#
# Elasticsearch custom HTTP headers to add to each request:
#
#elasticsearch.headers:
#  X-My-Header: Contents of the header
#
# Elasticsearch SSL settings:
#
#elasticsearch.ssl.enabled: false
#elasticsearch.ssl.certificate:
#elasticsearch.ssl.certificate_authority:
#elasticsearch.ssl.key:
#elasticsearch.ssl.key_passphrase:
#elasticsearch.ssl.verify: true
#
# ------------------------------- Hosting & Network ---------------------------
#
# Define the exposed URL at which users will reach App Search.
# Defaults to localhost:3002 for testing purposes.
# Most cases will use one of:
#
# * An IP: http://255.255.255.255
# * A FQDN: http://example.com
# * Shortname defined via /etc/hosts: http://app-search.search
#
#app_search.external_url: http://localhost:3002
#
# Web application listen_host and listen_port.
# Your application will run on this host and port.
#
# * app_search.listen_host: Must be a valid IPv4 or IPv6 address.
# * app_search.listen_port: Must be a valid port number (1-65535).
#
#app_search.listen_host: 127.0.0.1
#app_search.listen_port: 3002
#
# ------------------------------ Authentication -------------------------------
#
# The origin of authenticated App Search users.
# Options are standard, elasticsearch-native, and elasticsearch-saml.
#
# Docs: https://swiftype.com/documentation/app-search/self-managed/security
#
# * standard: Users are created within the App Search dashboard.
# * elasticsearch-native: Users are managed via the Elasticsearch native realm.
# * elasticsearch-saml: Users are managed via the Elasticsearch SAML realm.
#
#app_search.auth.source: standard
#
# (SAML only) Name of the realm within the Elasticsearch realm chain.
#
#app_search.auth.name:
#
# ---------------------------------- Workers ----------------------------------
#
# Configure the number of worker threads.
#
#worker.threads: 4
#
# ----------------------------------- APIs ------------------------------------
#
# Set to true hide product version information from API responses.
#
#hide_version_info: false
#
# ---------------------------------- Mailer -----------------------------------
#
# Connect App Search to a mailer.
# Docs:
#   https://swiftype.com/documentation/app-search/self-managed/configuration
#
#email.account.enabled: false
#email.account.smtp.auth: plain
#email.account.smtp.starttls.enable: false
#email.account.smtp.host: 127.0.0.1
#email.account.smtp.port: 25
#email.account.smtp.user:
#email.account.smtp.password:
#email.account.email_defaults.from:
#
# ---------------------------------- Logging ----------------------------------
#
# Choose your log export path.
#
#log_directory: log
#
# Log level can be: debug, info, warn, error, fatal, or unknown.
#
#log_level: info
#
# Log format can be: default, json
#
#log_format: default
#
# Choose your Filebeat logs export path.
#
#filebeat_log_directory: log
#
# Enable logging app logs to stdout (enabled by default).
#
#enable_stdout_app_logging: true
#
# Enable ECS-style API and Analytics Logs.
#
#enable_ecs_logs: false
#
# ---------------------------------- TLS/SSL ----------------------------------
#
# Configure TLS/SSL encryption.
#
#app_search.ssl.enabled: false
#app_search.ssl.keystore.path:
#app_search.ssl.keystore.password:
#app_search.ssl.keystore.key_password:
#app_search.ssl.redirect_http_from_port:
#
# ---------------------------------- Session ----------------------------------
#
# Set key to persist user sessions through process restarts.
#
#secret_session_key:
#
# ----------------------------- Diagnostics report ----------------------------
#
# Path where diagnostic reports will be generated.
#
#diagnostic_report_directory: diagnostics


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM