1

I am using External File field in solr for my frequently updated types of data. I had created a file _external_<myfieldTypename> in my Index directory. And my data is like :

4950 = 150.0
4951 = 65.0
4952 = 789.0
4953 = 786.0
4954 = 5.0
4955 = 21.0

Now I had created new field as:

<fieldType name="<myfieldTypename>" class="solr.ExternalFileField" keyField="Name" defVal="1" indexed="false" stored="false" valType="float"/>

<field name="MyFieldName" type="<myfieldTypename>" indexed="true" stored="true"/>

My question is that how can I read data from my external file?

Thanks in advance.

Dharmik Bhandari
  • 1,702
  • 5
  • 29
  • 60

2 Answers2

3

Documentation :-

Solr looks for the external file in the index directory under the name of external_<fieldname> or external_<fieldname>.*

So in your case the external field file name should be MyFieldName.txt or external_MyFieldName.txt with the data.

External fields are not searchable. They can be used only for function queries or display.

Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • It has been already created. but Is there any way or query that will be executed from Solr admin and we can see it whether that field contains data or not? – Dharmik Bhandari Dec 05 '12 at 11:50
  • you should be able to get the data back in the response, so you can if the value exists or not. – Jayendra Dec 05 '12 at 11:51
  • I've already gone through that documentation and have done all steps but I dont know how to verify? – Dharmik Bhandari Dec 05 '12 at 11:51
  • when you query Solr for the record q=id:something or q=*:* you should be able to receive the data back in the response. – Jayendra Dec 05 '12 at 11:53
  • Suppose, id is 4950 and have mapped with value in external file. So when request like "Id:4950" in solr admin query browser, i didn't get any data from that field even didn't get that field. – Dharmik Bhandari Dec 05 '12 at 11:55
  • http://:/solr//select?q=id:4950 ... should return the record. If it doesn't, the record does not exist. – Jayendra Dec 05 '12 at 11:59
  • I got all fields except external file field. – Dharmik Bhandari Dec 05 '12 at 12:00
  • does the file abide to the naming convention ? and did you do an reindexing ?? – Jayendra Dec 05 '12 at 12:05
  • Still not getting output after re indexing. Is there any problem in defining my field type? And field? – Dharmik Bhandari Dec 05 '12 at 12:23
  • 1
    thats strange. Can you recheck if you have the file with the naming convention and case as specified in the answer and its in the index directory of your collection. You can check the logs to confirm its being loaded. – Jayendra Dec 05 '12 at 13:04
  • I agree with Jayendra's last comment. Based on the Documentation link provided in this answer, you do not have the name of the external file or fieldType defined properly. – Paige Cook Dec 05 '12 at 13:09
  • Is external file name should be as external file field name or field type name? Please advice. Because some sites are saying different different names? – Krutal Modi Dec 06 '12 at 05:38
  • http://lucene.apache.org/solr/api-4_0_0-ALPHA/org/apache/solr/schema/ExternalFileField.html mentions it should be the field name. – Jayendra Dec 06 '12 at 07:33
  • Thanks jayendra. My fieldtype is "" and field is "" and got error... http://i48.tinypic.com/2pzcls6.png .... Am i doing wrong or what? – Dharmik Bhandari Dec 06 '12 at 08:25
  • cant make out much from the error and the write method in the java file directly throws this exception. So the question is why is this method called. Did you clean up and reindex the complete data again ? – Jayendra Dec 06 '12 at 08:44
  • Yes We did reindex but no response found. – Krutal Modi Dec 06 '12 at 08:50
  • @Jayendra How to check into the logs whether the file / field is being loaded or not? – Krunal Dec 06 '12 at 11:35
  • When I trying to request " http://localhost:8983/solr/core-live/select/?q=*%3A*&version=2.2&start=0&rows=100&indent=on&sort=mostpopularproduct%20desc " got another error.....http://i49.tinypic.com/25ktrhd.png – Dharmik Bhandari Dec 06 '12 at 11:37
  • Can we use external field for ordering? – Krunal Sep 10 '13 at 06:49
  • external fields can be used in function queries and sort can support function queries. Also you can try using the standalone field for sort should work seamlessly. – Jayendra Sep 10 '13 at 06:54
3

how can I read data from my external file?

Asked the same question to solr-user group. (See here.) Yonik Seely's answer in that thread works fine for me in Solr 4.2.1. The syntax to use is:

fl=*,field(external_file_field)

You can also alias it, like Yonik says:

fl=*,views:field(external_file_field)

arun
  • 10,685
  • 6
  • 59
  • 81