can i use copyfield or dynamicfield or multivalued field functionality in solrnet? - solrnet

can any body explain how during indexing i can use copyfield or dynamicfield or multivalued field functionality usin solrnet

Map multiValued fields to ICollection<T> properties:
[SolrField("features")]
public ICollection<string> Features {get;set;}
I just updated the docs about mapping dynamicFields.

Related

Problem indexing LongField from custom FieldBridge

for a search using lucene, I made a bridge,
public class EntityIDFieldBridge implements FieldBridge {
#Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
BaseEntity baseEntity = (BaseEntity) value;
if(value !=null){
Field field = new LongField(name, baseEntity.getId(),Field.Store.NO);
document.add(field);
}
}
}
when I search for the value, I dont get the correct documents. when I search term:* I do get the ones that are not null, so I see that its getting indexed.... StringField is working fine. But I think it should be a long field. Any ideas?
Based on the little information you provided, I am assuming that you are not trying to get a value whihc is null.
Field Bridge provided more information on what it is, what lucene supports and how it works:
In Lucene all index fields have to be represented as Strings. For this
reason all entity properties annotated with #Field have to be indexed
in a String form. For most of your properties, Hibernate Search does
the translation job for you thanks to a built-in set of bridges. In
some cases, though you need a more fine grain control over the
translation process.
Also for Null values
null elements are not indexed. Lucene does not support null elements
and this does not make much sense either.

spring-data-mongodb using the fieldName instead of _id

I have a Pojo with an attribute as
Class A{
#Id
#Field("item_id")
private String itemId;
}
When i try to update a document in MongoDB collection based on the itemId as below, it worked well and able to see from mongo ops logs that the query was transformed as "_id in itemIds "
Query query = new Query(Criteria.where("itemId").in(itemIds));
Update update = new Update();
update.set("field2", "abd");
mongoTemplate.updateMulti(query, update, A.class)
When i upgraded to spring-data-mongodb-2.1.5.RELEASE, the query i saw in the mongo logs was "item_id in itemIds". Since item_id is not a field and no index for that field in the collection, the query took forever to complete.
Any help to understand why the spring-data library is building the query as _id in older version and using the field as it is in newer version?
After a 2 minute search on the Spring documentation (https://docs.spring.io/spring-data/mongodb/docs/1.3.3.RELEASE/reference/html/mapping-chapter.html):
The following outlines what field will be mapped to the '_id' document field:
A field annotated with #Id (org.springframework.data.annotation.Id) will be mapped to the '_id' field.
A field without an annotation but named id will be mapped to the '_id' field.
Did you try that already?

Elasticsearch: Do I need to index '_id' filed specifically?

Looks like _id field is automatically mapped to _uid by the Elasticsearch.
I have below query to get a document by passing document's _id
query: {
match: {
_id: myDocumentId
}
}
Should I specify indexing for _id field to make above query work fast or is it taken care by using _uid filed internally?
You can just use
GET /<index_name>/<type_name>/<myDocumentId>

Spring Elastic Search Custom Field names

I am new to Elastic Search and I am trying to implement it using Spring-data-elasticsearch.
I have fields with names such as "Transportation", "Telephone_Number" in our elastic search documents.
When I try to map my #Domain object fields with those, I don't get any data for those as I couldn't successfully map those fields.
Tried to use #Field, was disappointed as it didn't have 'name' property in it to map with custom field name.
Tried different variations of a GETTER function, none of those seem to be mapping to those fields.
I started wondering if there's something I'm missing here.
How does a domain object field look like which should map to a filed called something like "Transportation" ?
Any help appreciated
You can use custom name. Spring Data ES use Jackson. So, you can use #JsonProperty("your_custom_name") to enable custom name in ES Mapping
for example:
#Document(indexName = "your_index_name", type = "your_type_name")
public class YourEntity {
....
#JsonProperty("my_transportation")
#Field(type = FieldType.String, searchAnalyzer = "standard", indexAnalyzer = "standard", store = true) // just for example
private String myTransportation;
....
}
Note: I'm sorry anyway, my english is bad.. :D

Elasticsearch NEST - SortAsceding doesn't sorts documents

I am trying to sort the result set based on a field name. But Sort doesn't works with string type.
Tried Code:-
public class Company
{
public long Number { get; set; }
public string Name{ get; set; }
}
My problem is : Sorting is not done when I use SortAscending API, like below
var resultSet = client.Search<Article>(s => s
.Type("Company")
.From(0)
.Size(200)
.QueryString("Stack OverFlow")
.SortAscending(f => f.Name));
Note: Documents are listed as Sorted if I set field name as Number(f => f.Number)
Please help
Your issue with sorting on the name field in your index is probably related to the fact that the field is being analyzed/tokenized. From the Elasticsearch Sort Guide:
For string based types, the field sorted on should not be analyzed / tokenized.
Therefore, you need to provide an additional field that is not analyzed/tokenized to perform your sort against. You can accomplish this by adding an additional field to your documents and setting the mapping for that type/field to not_analyzed or you can leverage multi_field (now just fields in version 1.x) on your existing name field. Please refer to the following for guidance on how to accomplish either of these options:
Multi-Fields (or Fields in v1.X)
Mapping

Resources