[英]Query a specific index value in a multivalue field in Solr
所以我的Solr文檔中有以下多字段(僅作為示例)。
"type": [
"Single",
"Series",
"Other association"
],
"name": [
"Name associated with first type",
"Name associated with second type",
"Name associated with third type"
]
我可以用以下方法查詢這兩個字段:
name:"Name associated with third type" AND type:"Series"
但我需要查詢name
的值,並匹配同一數組索引中的type
值。 所以,上面的例子不應該打,因為“與第三類相關的名稱”是第三name
和“系列”是第二次在type
。
應該產生命中的查詢是這樣的,因為兩個值都在同一個數組索引中。
name:"Name associated with second type" AND type:"Series"
但這符合一切。 我希望這是正確解釋的。 我甚至不知道這是否可行。
不,不可能匹配具有相同索引的兩個多值字段。 您需要獲取所有匹配的文檔並在客戶端處理它們。
但是,如果您始終擁有type
和name
的完整值,則可以更改架構並使其像這樣工作。
定義一個名為type_names
的新字段,它是一個多值字符串字段。 修改索引器以在該字段中設置值
type_names: [Single#Name associated with first type,
Series#Name associated with second type,
Other association#Name associated with third type]
我正在使用#
但您可以使用任何適合您的分隔符字符串。
(如果您想要不區分大小寫的匹配以及小寫查詢值,您可能希望小寫索引中的所有內容。)
然后查詢此字段,如:
type_names:(Series#Name associated with second type)
如果您知道type
的完整值但name
只有一個單詞(比如second
),則可以使用正則表達式匹配:
type_names:/Series#.*second.*/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.