Indexing and querying CQL3 collection map in Solr

2019-06-04 22:00发布

问题:

The following documentation page from Datastax states:

DSE Search maps collections as follows:
     Collection list and set: multi-valued field
     Collection maps: dynamic field
The name of the dynamic field minus the wildcard is the map name. For example, a map column name dyna* is mapped to dyna. Inner keys are mapped to the full field name.

The last statement is not very clear to me. How exactly should the field definition look like? Assuming that I have a collection map defined as scores map<int,int> in CQL3, is the following field definition correct?

<field name="scores*" type="int" indexed="true" stored="true"/>

And how do I query this? Assuming that the map's value is {201409 : 89, 201410 : 67} and I want to filter on inner field '201410', is the following correct?:

fq=scores201410:[80 TO *]

回答1:

The name of the dynamic field minus the wildcard is the map name means that the following dynamic field corresponds to the following map name in CQL:

dynamic field: <dynamicField name="lang_*" . . . > map name: CREATE TABLE hits ( . . .lang_ map<text, text>, . . .);

In your example, dynamic field name = scores_*.

The query depends on the values you insert into the fields. If you insert these values into the CQL scores_ column:

{ 'scores_100'  : '5000'}
 { 'scores_200'  : '10000'}
 { 'scores_100'  : '300'}

then, I think the query to get all the scores_100 in the collection would be:

http://:8983/solr/mykeyspace.myscores/select?q=scores_100%3A*&wt=xml&indent=true