You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Kamaljeet Kaur <ka...@gmail.com> on 2013/08/23 16:31:52 UTC

Index a database table?

Hello there,

I just got something to index mysql database talble:
http://wiki.apache.org/solr/DIHQuickStart

Pasted the following in config tag of solrconfig.xml file
(solr-4.4.0/example/solr/collection1/conf/solrconfig.xml):

<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
  <str name="config">data-config.xml</str>
</lst>
</requestHandler>

Altering the next code, making a data-config.xml file, I have written the
following, where I am not sure if "driver", "url" and "entity name" are
correct or not. How do I know if they are wrong? Because the model name (
table name ) i.e. "tcc_userprofile" and its attributes are written in
"query" and I know they are right. "New" is myql database name.

<dataConfig>
  <dataSource type="JdbcDataSource" 
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost/New" 
              user="root" 
              password="password"/>
  <document>
    <entity name="id" 
            query="select id,first_name from tcc_userprorofile">
    </entity>
  </document>
</dataConfig>




--
View this message in context: http://lucene.472066.n3.nabble.com/Index-a-database-table-tp4086334.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Index a database table?

Posted by Shawn Heisey <so...@elyograg.org>.
On 8/23/2013 10:27 PM, Kamaljeet Kaur wrote:
> 
> Actually I wanted every single step to be clear, thats why I asked.
> Now there is written:
> 
> "Ensure that your solr schema (schema.xml) has the fields 'id',
> 'name', 'desc'. Change the appropriate details in the data-config.xml"
> 
> My schema.xml is not having these fields. That means I have to declare
> them. Can you tell me where? Where to declare them in that file? Isn't
> there the same option as in solr 3.5.0, Using a command, schema was
> built and we placed that output in schema.xml file?

You don't necessarily need these specific fields, unless these fields
are present in your database table, or they are present in your
data-config.xml file as field conversions.  Whatever you end up with
between your SELECT statement and data-config.xml is what you need in
your schema.

The only time a field with the exact name "id" is required is if you are
using SolrCloud with a numShards value higher than 1 and you expect Solr
to distribute your documents between your shards automatically.

> Also its written:
> 
> "Drop your JDBC driver jar file into the <solr-home>/lib directory."
> 
> It's a Java application to interact with database. Where is it? It
> must be a .jar file, rest I don't know yet. My solr/example/lib
> directory has an ext directory, jetty drivers and a
> servlet-api-3.0.jar driver. Is it fine? Then which one is JDBC driver?

It's not a full application, it's a Java library that translates between
your database and the JDBC layer provided by Java.  Your database vendor
will likely have a JDBC driver available.

The driver file that I use for connecting to a mysql database is named
mysql-connector-java-5.1.26-bin.jar and is available from
http://dev.mysql.com/downloads/connector/j/ .  If you are not using
mysql, then you would need to find the driver jar for your database, and
you would need to figure out the right driver name and URL information
to use in dataconfig.xml.

The solr/example/lib directory is for jetty, not Solr.  You should have
a solr.xml file that configures Solr.  The place where that file lives
is the solr home.  Jars for Solr work best in ${solr.solr.home}/lib.
The default solr.solr.home value is ./solr which is relative to the
current working directory when Jetty (or another container) is started.

Thanks,
Shawn


Re: Index a database table?

Posted by Andrea Gazzarini <an...@gmail.com>.
 > Actually I wanted every single step to be clear, thats why I asked.
 > Now there is written:
 >
 > "Ensure that your solr schema (schema.xml) has the fields 'id',
 > 'name', 'desc'. Change the appropriate details in the data-config.xml"
 >
 > My schema.xml is not having these fields. That means I have to declare
 > them. Can you tell me where? Where to declare them in that file? Isn't
 > there the same option as in solr 3.5.0, Using a command, schema was
 > built and we placed that output in schema.xml file?
 >

No, there's no magic. You should just know what is the SOLR schema and 
how to define fields and types. That's all. You can find all what you 
need here:

http://wiki.apache.org/solr/SchemaXml

Read carefully and create / change your schema with those fields.

 > Also its written:
 >
 > "Drop your JDBC driver jar file into the <solr-home>/lib directory."
 >

You don't have mysql driver. They are not shipped with jetty or solr. Go 
here

http://dev.mysql.com/downloads/connector/j/

And download the apprpriate version. Next, place that jar in the "lib" 
directory under solr/collection1 (if there's no such dir create it first).


Re: Index a database table?

Posted by Kamaljeet Kaur <ka...@gmail.com>.
On Fri, Aug 23, 2013 at 11:17 PM, Andrea Gazzarini-3 [via Lucene]
<ml...@n3.nabble.com> wrote:
> Why don't you try?


Actually I wanted every single step to be clear, thats why I asked.
Now there is written:

"Ensure that your solr schema (schema.xml) has the fields 'id',
'name', 'desc'. Change the appropriate details in the data-config.xml"

My schema.xml is not having these fields. That means I have to declare
them. Can you tell me where? Where to declare them in that file? Isn't
there the same option as in solr 3.5.0, Using a command, schema was
built and we placed that output in schema.xml file?

Also its written:

"Drop your JDBC driver jar file into the <solr-home>/lib directory."

It's a Java application to interact with database. Where is it? It
must be a .jar file, rest I don't know yet. My solr/example/lib
directory has an ext directory, jetty drivers and a
servlet-api-3.0.jar driver. Is it fine? Then which one is JDBC driver?



-- 
Kamaljeet Kaur

kamalkaur188.wordpress.com
facebook.com/kaur.188




--
View this message in context: http://lucene.472066.n3.nabble.com/Index-a-database-table-tp4086334p4086437.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Index a database table?

Posted by Andrea Gazzarini <an...@gmail.com>.
Seems ok assuming that

- you have mysql driver jar in your $SOLR_HOME/lib
- New is database name
- user root / password is valid
- table exists
- SOLR has a schema with the following id and first_name fields declared

About "How do I know if they are wrong?"

Why don't you try?


On 08/23/2013 04:31 PM, Kamaljeet Kaur wrote:
> Hello there,
>
> I just got something to index mysql database talble:
> http://wiki.apache.org/solr/DIHQuickStart
>
> Pasted the following in config tag of solrconfig.xml file
> (solr-4.4.0/example/solr/collection1/conf/solrconfig.xml):
>
> <requestHandler name="/dataimport"
> class="org.apache.solr.handler.dataimport.DataImportHandler">
> <lst name="defaults">
>    <str name="config">data-config.xml</str>
> </lst>
> </requestHandler>
>
> Altering the next code, making a data-config.xml file, I have written the
> following, where I am not sure if "driver", "url" and "entity name" are
> correct or not. How do I know if they are wrong? Because the model name (
> table name ) i.e. "tcc_userprofile" and its attributes are written in
> "query" and I know they are right. "New" is myql database name.
>
> <dataConfig>
>    <dataSource type="JdbcDataSource"
>                driver="com.mysql.jdbc.Driver"
>                url="jdbc:mysql://localhost/New"
>                user="root"
>                password="password"/>
>    <document>
>      <entity name="id"
>              query="select id,first_name from tcc_userprorofile">
>      </entity>
>    </document>
> </dataConfig>
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Index-a-database-table-tp4086334.html
> Sent from the Solr - User mailing list archive at Nabble.com.