0

I am using solr to retrieve results from a cassandra table.

Table structure:

CREATE TABLE mytable (
  field1 uuid,
  field2 text ,
  bfield blob,
  cstdta_<text, text>,
  PRIMARY KEY (field1)
);

Table content

INSERT INTO mytable  VALUES ( 62c36092-82a1-3a00-93d1-46196ee77204,"test", { 'f1'  : 'La Vita E La Felicita', 'f2' : 'Michele Bravi' });

I am able to retrieve the results when queried directly using devcenter. But on using solr query, the dynamic field is not returned.

Solr query Response:

{
  "responseHeader": {
    "status": 0,
    "QTime": 1
  },
  "response": {
    "numFound": 1,
    "start": 0,
    "docs": [
      {
        "field1": "62c36092-82a1-3a00-93d1-46196ee77204",
        "field2": "test"

      }
    ]
  }
}

Here is the scheme.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<schema name="autoSolrSchema" version="1.5">
<types>
<fieldType class="org.apache.solr.schema.TextField" name="TextField">
<analyzer>
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>

<fieldType class="org.apache.solr.schema.UUIDField" name="UUIDField"/>
<fieldType class="org.apache.solr.schema.BinaryField" name="BinaryField"/>
</types>
<fields>
<field indexed="true" multiValued="false" name="field1" stored="true" type="TextField"/>
<field indexed="true" multiValued="false" name="field2" stored="true" type="TextField"/>
<field indexed="true" multiValued="false" name="bfield" stored="true" type="BinaryField"/>
<dynamicField indexed="true" multiValued="false" name="cstdta_*" stored="true" type="TextField"/>
<field indexed="true" multiValued="false" name="cstdta_stc" stored="true" type="TextField"/>
<copyField source="cstdta_*" dest="cstdta_stc"/>
</fields>
<uniqueKey>resid</uniqueKey>
</schema>

I added the copy field following this answer. But it doesn't seem to work.

UPDATE:

As user3398164 pointed out I needed to insert customdata inside the dynamic field in a specific format. In my case, I had to insert using this query:

 INSERT INTO mytable  VALUES ( 62c36092-82a1-3a00-93d1-46196ee77204,"test", { 'cstdtaf1'  : 'La Vita E La Felicita', 'cstdtaf2' : 'Michele Bravi' });

Now I am getting the desired result:

{
  "responseHeader": {
    "status": 0,
    "QTime": 1
  },
  "response": {
    "numFound": 1,
    "start": 0,
    "docs": [
      {
        "field1": "62c36092-82a1-3a00-93d1-46196ee77204",
        "field2": "test",
         "cstdtaf1":"La Vita E La Felicita",
         "cstdtaf2" : "Michele Bravi"
      }
    ]
  }
}
Community
  • 1
  • 1
Sharun
  • 3,022
  • 6
  • 30
  • 59

1 Answers1

1

@Sharun Try inserting the data as mentioned in the below link https://docs.datastax.com/en/datastax_enterprise/4.6/datastax_enterprise/srch/srchDynFlds.html

Copied from the reference site:

In CQL, to define the map collection column, use the same base name (no asterisk) as you used for the field in the schema.xml. For example, use dyna_* in the schema.xml and dyna_ for the name of the CQL map collection.

Use type text for the map key. For example:

CREATE TABLE my_dynamic_table ( . . . dyna_ map, . . . ); Using CQL, insert data into the map using the base name as a prefix or suffix in the first component of each map pair. The format of the map using a prefix is: { prefix_literal : literal, prefix_literal : literal, . . . }

For example, the CQL map looks like this: 'dyn_' : {dyn_1 : 1, dyn_2 : 2, dyn_3 : 3}

Sharun
  • 3,022
  • 6
  • 30
  • 59