简体   繁体   English

在多值字段上被Solr查询阻止

[英]blocked by a solr query on multivalued fields

I have a problem on a logical solr query. 我对逻辑Solr查询有问题。 Here is my index structure : 这是我的索引结构:

"docs":[
        {
    "id":"doc1",
     "type.id": [
              "1",
              "2",
              "3"
            ],
            "type.demande": [
              "non",
              "non",
              "oui"
            ],
            "type.reponse": [
              "oui",
              "oui",
              ""
            ],
            "type.traitement": [
              "oui",
              "oui",
              "non"
            ]

    },
    {
    "id":"doc2",
     "type.id": [
              "1",
              "2",
              "3"
            ],
            "type.demande": [
              "non",
              "non",
              "non"
            ],
            "type.reponse": [
              "oui",
              "oui",
              "non"
            ],
            "type.traitement": [
              "oui",
              "oui",
              ""
            ]
    }
    ]

Each field type.id, demande, reponse and traitement are multivalued. 每个字段type.id,demande,reponse和traitement都是多值的。 Each type is a group of these 4 fields. 每种类型都是这4个字段的组。 Ex. 例如 : type id 1 from doc 2 has demande "non", réponse "oui", traitement "oui". :文档2中的id 1类型具有需求“ non”,响应“ oui”,特征“ oui”。 I want to do a query of the last value of these fields to filter on values of the last inserted type. 我想查询这些字段的最后一个值以筛选最后插入类型的值。 For example of solr query : 例如solr查询:

q=(type.demande:"oui" AND (type.reponse:"" OR type.reponse:"non"))

When I try this query, it seems that solr will search any value matching on the fields. 当我尝试此查询时,似乎solr将搜索字段上匹配的任何值。 I searched on solr docs, but I didn't find a proposal of "last" or "lastValueOf" which can permit me to do this. 我搜索了solr文档,但没有找到可以允许我执行的“ last”或“ lastValueOf”提议。

Thanks. 谢谢。

You can't with flat documents, really - but you can do it with child documents . 确实不能使用平面文档-但可以使用子文档来实现 There's an easier solution if this is the only scenario you're querying, and that is to create a secondary value that you filter against - a merged form of these fields that you can query as a single value. 如果这是您要查询的唯一方案,那么有一个更简单的解决方案,那就是创建要过滤的辅助值-这些字段的合并形式,您可以将其作为单个值进行查询。

When indexing you'd merge the values into a single field with a separator, for example | 编制索引时,可以将值合并到带有分隔符的单个字段中,例如| , then query it as a single field: ,然后将其作为单个字段进行查询:

merged_demande_reponse:("oui|non" OR "oui|")

This field should not be processed further in any way. 不应以任何方式进一步处理此字段。 The good thing about this solution is that each document is kept plain and all functionality works out of the box without having to think about child documents each time. 此解决方案的优点是,每个文档都保持简洁,并且所有功能都可以立即使用,而不必每次都考虑子文档。

Another solution is to index each combination as a document by itself (which is what child documents does in the background). 另一个解决方案是将每个组合单独索引为文档(子文档在后台执行的操作)。 Each combination of values becomes its own document with a common id: 值的每个组合都变成具有共同ID的自己的文档:

{
  "id": <generated id>,
  "docid": "doc1",
  "type.id": "1",
  "type.demande": "non"
  "type.reponse": "oui"
  "type.traitement": "oui"
},
{
  "id": <generated id>,
  "docid": "doc1",
  "type.id": "2",
  "type.demande": "non"
  "type.reponse": "oui"
  "type.traitement": "oui"
},
... etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM