Setting Fuzziness to Auto for MatchQuery - elasticsearch

I'm using the fuzziness option for my MatchQuery, however I want to set the Fuzziness value to auto. Is there any way to do this?
Also, for the completion suggester you can set it to be unicode aware, is there any way to do this for my MatchQuery?
This is how I create the request:
var request = new SearchRequest<object>
{
Types = types,
Size = 5,
Query = new QueryContainer(new MatchQuery
{
Field = new PropertyPathMarker { Name = "ProductName.autocomplete" },
Query = q,
Fuzziness = 2.0
}),
Fields = new[]
{
new PropertyPathMarker{Name = "ProductName"}
}
};
return _client.Search<object>(request);

Sadly at the moment you cant everywhere, we have a specialised interface that can represent all fuzziness states but not all places taking a fuzziness parameter use it.
We received a pull request for this that we merged into our 2.0 branch since its a breaking change:
https://github.com/elasticsearch/elasticsearch-net/pull/941
We have no ETA on a 2.0 release as of yet though.

Related

Code base mapping in NEST 2.0

My application is using dynamic data and fields are configurable by end user.
It was working fine using Code Base Mapping similar that was described in NEST example on page Put Mapping example
var indexDefinition = new RootObjectMapping
{
Properties = new Dictionary<PropertyNameMarker, IElasticType>(),
Name = indexName
};
var property = new StringMapping
{
Index = "not_analyzed"
};
var analyzedField = new StringMapping
{
Index = "analyzed"
};
property.Fields.Add("name_analyzed", analyzedField);
indexDefinition.Properties.Add("name", property);
this.ConnectedClient.Map<object>(x => x.InitializeUsing(indexDefinition));
I wanted to convert my application to use elastic search 2.2 and nest 2.x but the problem is that most of classes that I've used are gone see breaking changes v2
I was using RootObjectMapping, MultiFieldMapping and StringMapping and all of those classes are gone.
The problems is that there is a lack of documentation for NEST 2.0.
Can somebody provide me example of code base mapping similar to example for code base mapping?
Thanks

Bulk Update on ElasticSearch using NEST

I am trying to replacing the documents on ES using NEST. I am seeing the following options are available.
Option #1:
var documents = new List<dynamic>();
`var blkOperations = documents.Select(doc => new BulkIndexOperation<T>`(doc)).Cast<IBulkOperation>().ToList();
var blkRequest = new BulkRequest()
{
Refresh = true,
Index = indexName,
Type = typeName,
Consistency = Consistency.One,
Operations = blkOperations
};
var response1 = _client.Raw.BulkAsync<T>(blkRequest);
Option #2:
var descriptor = new BulkDescriptor();
foreach (var eachDoc in document)
{
var doc = eachDoc;
descriptor.Index<T>(i => i
.Index(indexName)
.Type(typeName)
.Document(doc));
}
var response = await _client.Raw.BulkAsync<T>(descriptor);
So can anyone tell me which one is better or any other option to do bulk updates or deletes using NEST?
You are passing the bulk request to the ElasticsearchClient i.e. ElasticClient.Raw, when you should be passing it to ElasticClient.BulkAsync() or ElasticClient.Bulk() which can accept a bulk request type.
Using BulkRequest or BulkDescriptor are two different approaches that are offered by NEST for writing queries; the former uses an Object Initializer Syntax for building up a request object while the latter is used within the Fluent API to build a request using lambda expressions.
In your example, BulkDescriptor is used outside of the context of the fluent API, but both BulkRequest and BulkDescriptor implement IBulkRequest so can be passed to ElasticClient.Bulk(IBulkRequest).
As for which to use, in this case it doesn't matter so whichever you prefer.

Not able to set fuzziness as auto in MultiMatch Query

I am trying to use a multimatch query by instantiating an object of the following type:
MultiMatchQuery query = new MultiMatchQuery()
{
Query = searchString,
Fuzziness = 6, //TODO Need to set AUTO Here
Fields = new PropertyPathMarker[] { "title", "hTexts.htext", "tnText" }
});
As seen above, I am setting fuzziness to 6, but I need to set it to auto. How do I do it?
Not yet possible, but pretty soon in version 2.0.0: https://github.com/elastic/elasticsearch-net/pull/941

Is there a way to get results of solr grouping using Solr Net

I want to try new solr collapsing/grouping included in solr 3.3, i have tried queries on solr Admin page and that works absolutely right but when I try to query in my c# code using solr net that does not seem to work as expected. Here is how I am setting the param values
options.ExtraParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string,string>("group","true"),
new KeyValuePair<string,string>("group.field","AuthorID"),
};
Yes, you can use Grouping (formerly known as Field Collapsing) with SolrNet, it was introduced in the SolrNet 0.4.0 alpha1 release. Here are the release notes on the author's blog about this support being added in. So you will need to grab that version (or later) from Google Code(binaries) or GitHub(source). Also here is an example of using grouping from the unit tests in the source - Grouping Tests
public void FieldGrouping()
{
var solr = ServiceLocator.Current.GetInstance<ISolrBasicOperations<Product>>();
var results = solr.Query(SolrQuery.All, new QueryOptions
{
Grouping = new GroupingParameters()
{
Fields = new [] { "manu_exact" },
Format = GroupingFormat.Grouped,
Limit = 1,
}
});
Console.WriteLine("Group.Count {0}", results.Grouping.Count);
Assert.AreEqual(1, results.Grouping.Count);
Assert.AreEqual(true, results.Grouping.ContainsKey("manu_exact"));
Assert.GreaterThanOrEqualTo(results.Grouping["manu_exact"].Groups.Count,1);
}

Lucene.NET - sorting by int

In the latest version of Lucene (or Lucene.NET), what is the proper way to get the search results back in sorted order?
I have a document like this:
var document = new Lucene.Document();
document.AddField("Text", "foobar");
document.AddField("CreationDate", DateTime.Now.Ticks.ToString()); // store the date as an int
indexWriter.AddDocument(document);
Now I want do a search and get my results back in order of most recent.
How can I do a search that orders results by CreationDate? All the documentation I see is for old Lucene versions that use now-deprecated APIs.
After doing some research and poking around with the API, I've finally found some non-deprecated APIs (as of v2.9 and v3.0) that will allow you to order by date:
// Find all docs whose .Text contains "hello", ordered by .CreationDate.
var query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Text", new StandardAnalyzer()).Parse("hello");
var indexDirectory = FSDirectory.Open(new DirectoryInfo("c:\\foo"));
var searcher = new IndexSearcher(indexDirectory, true);
try
{
var sort = new Sort(new SortField("CreationDate", SortField.LONG));
var filter = new QueryWrapperFilter(query);
var results = searcher.Search(query, , 1000, sort);
foreach (var hit in results.scoreDocs)
{
Document document = searcher.Doc(hit.doc);
Console.WriteLine("\tFound match: {0}", document.Get("Text"));
}
}
finally
{
searcher.Close();
}
Note I'm sorting the creation date with the LONG comparison. That's because I store the creation date as DateTime.Now.Ticks, which is a System.Int64, or long in C#.

Resources