标题翻译
How to configure POJO so it index integer value as text instead of integer?
问题
我试图使用代码在Apache Solr中加载数据。由于我对此相对陌生,我编写了以下代码来加载数据,但是当我在Solr中查看数据时,它已将整数值索引为整数,而我希望它默认情况下索引为文本。我该如何做到这一点?
public class ARHts {
@Field("section")
private String section;
@Field("hts_no")
private String hsNo;
@Field("description")
private String description;
}
这里的 hts_no
被索引为整数,我希望它被索引为文本。
英文翻译
I am trying to load data in apache solr using code. Being relatively new to this i wrote the following Code to load the data but when i see the data in solr it has indexed the integer values on integer which it should do by default i want it to be indexed as text. How i can do the same?
public class ARHts {
@Field("section")
private String section;
@Field("hts_no")
private String hsNo;
@Field("description")
private String description;
}
here hts_no is getting indexed as integer i want it to be indexed as text.
答案1
得分: 0
通常情况下,您需要在服务器端进行此操作(在某些较大的实现中可能会有所不同,我不确定 spring-boot-implementation 允许什么)。在开始索引内容之前,将字段 hts_no
定义为字符串字段(如果您还想进行非精确搜索,则可以定义为文本字段)。
您可以使用模式 API来定义字段及其类型:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name": "hts_no",
"type": "string",
"stored": true,
"indexed": true }
}' http://localhost:8983/solr/collectionname/schema
... 或者您可以使用旧的 schema.xml
配置(请注意,这可能已被复制到 managed-schema
)。
<field name="hts_no" type="string" indexed="true" stored="true" />
英文翻译
You'll usually have to do that on the server side (might differ in some larger implementations, I'm not sure what the spring-boot-implementation allows) by defining the field hts_no
as a string field (or as a text field if you want to do non-exact searches as well) before starting to index your content.
You can use the Schema API to define a field and its type:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name": "hts_no",
"type": "string",
"stored": true,
"indexed": true }
}' http://localhost:8983/solr/collectionname/schema
.. or you can use the older schema.xml
configuration (be aware that this may have been copied over to managed-schema
).
<field name="hts_no" type="string" indexed="true" stored="true" />
专注分享java语言的经验与见解,让所有开发者获益!
评论