Solr query with dynamic field

2019-08-08 21:20发布

问题:

I have documents with the following link.* dynamic fields:

"docs": [{
    "id":"id1" 
    "link.1.text":"mytext"
    "link.1.nImg":1
    "link.2.text":"mytext"
    "link.2.nImg":2
}, {
    "id":"id2" 
    "link.1.text":"mytext"
    "link.1.nImg":1
    "link.2.text":"mytext"
    "link.2.nImg":1
}]

How can I get a query like : link.*.text:"mytext" or link.*.nImg:2 ?

回答1:

You couldn't do that in Solr.

Dynamic fields allow Solr to index fields that you did not explicitly define in your schema. This is useful if you discover you have forgotten to define one or more fields. Dynamic fields can make your application less brittle by providing some flexibility in the documents you can add to Solr.

In query you need to list exact name of a field name, so dynamic fields give you an index time flexibility

Some more info - https://cwiki.apache.org/confluence/display/solr/Dynamic+Fields