簡體   English   中英

在 elasticsearch 中使用不同的文檔類型創建索引

[英]Create index in elasticsearch with different document types

我需要在彈性中索引“客戶”實體。 我的 object “CLIENT” 人由幾個片段(JSON 文檔)組成,例如

COMMON (firstname, lastname etc),
EDUCATION (fields...),
JOB (fields...) and so on. 

所以我的索引必須存儲所有這些段(JSON 文檔)。 然后我必須通過字段和段的不同組合進行搜索,例如: search word "university" in COMMON.firstname, COMMON.lastname, EDUCATION.field1, EDUCATION.field2 並且我可以將搜索結果作為包含所有細分的客戶列表返回嗎

我會說,文件可能看起來像這樣

{
  ...common properties,
  "education": {
    ...education properties
  },
  "job": {
    ...job properties
  }
}

為了索引這樣的文檔,您可以執行下一個查詢(新索引,如果不存在,將自動創建)

PUT /client/doc/1
{
  "firstName": "...",
  "lastName": "...",
  ...other common properties,
  "education": {
    ...education properties
  },
  "job": {
    ...job properties
  }
}

其中client是索引名稱, doc是類型, 1是新文檔的id。

然后您可以通過執行獲取客戶端列表(默認為 10)

GET /client/doc/_search

為了搜索,您可以執行(這也將返回最多 10 個文檔,因為 10 是默認值)

GET /client/doc/_search
{
  "query": {
    "query_string" : {
      "query" : "firstName:university OR lastName:university OR education.field1:university OR education.field1:university",
      "default_field" : "content"
    }
  }
}

如果您想為所有或部分屬性明確指定數據類型,請查看動態映射 否則,將根據值分配默認數據類型,例如字符串值的“文本”等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM