Code Monkey home page Code Monkey logo

elastic / elasticsearch-net Goto Github PK

View Code? Open in Web Editor NEW
3.5K 498.0 1.1K 158.59 MB

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.

Home Page: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html

License: Apache License 2.0

Shell 0.11% F# 0.20% C# 99.56% Batchfile 0.01% PowerShell 0.07% YAML 0.07%
elasticsearch nest c-sharp dot-net dot-net-client elasticsearch-net client

elasticsearch-net's Introduction

Elasticsearch .NET Client

Repository for Elastic.Clients.Elasticsearch the official .NET client for Elasticsearch. Older branches include both previous clients, NEST and Elasticsearch.Net.

Download the latest version of Elasticsearch or sign-up for a free trial of Elastic Cloud.

The .NET client for Elasticsearch provides strongly typed requests and responses for Elasticsearch APIs. It delegates protocol handling to the Elastic.Transport library, which takes care of all transport-level concerns (HTTP connection establishment and pooling, retries, etc.).

Compatibility

Language clients are forward compatible; meaning that the clients support communicating with greater or equal minor versions of Elasticsearch without breaking. It does not mean that the clients automatically support new features of newer Elasticsearch versions; it is only possible after a release of a new client version. For example, a 8.12 client version won't automatically support the new features of the 8.13 version of Elasticsearch, the 8.13 client version is required for that. Elasticsearch language clients are only backwards compatible with default distributions and without guarantees made.

Elasticsearch Version Elasticsearch-NET Branch Supported
main main
8.x 8.x 8.x
7.x 7.x 7.17

Installation

Refer to the Installation section of the getting started documentation.

Connecting

Refer to the Connecting section of the getting started documentation.

Usage

Documentation

Please refer to the full documentation on elastic.co for comprehensive information on installation, configuration and usage.

Versions

Elasticsearch 8.x Clusters

We have released the next generation of the .NET client for Elasticsearch, which aligns with v8 of Elasticsearch. We have renamed this library Elastic.Clients.Elasticsearch, and the packages are published on NuGet. The 8.0.x versions do not offer complete feature parity with the existing NEST client. We therefore recommend you thoroughly review our release notes and migration guidance before attempting to migrate existing applications to the Elastic.Clients.Elasticsearch library.

Until the new client supports all endpoints and features your application requires, you may continue to use the latest 7.17.x client to communicate with Elasticsearch v8 servers. Please review our documentation, which describes how to enable compatibility mode and secure communications with a v8 cluster.

Elasticsearch 7.x Clusters

We recommend using the latest 7.17.x NEST client to communicate with Elasticsearch v7 servers.

Contributing

See CONTRIBUTING.md

Copyright and License

This software is Copyright (c) 2014-2022 by Elasticsearch BV.

This is free software, licensed under The Apache License Version 2.0.

elasticsearch-net's People

Contributors

andersosthus avatar azubanov avatar bytenik avatar codebrain avatar efjoseph avatar ericberens avatar flobernd avatar freshmaker74 avatar github-actions[bot] avatar gmarz avatar gmoskovicz avatar jonyadamit avatar kevingessner avatar mariuszkerl avatar mpdreamz avatar nickcraver avatar niemyjski avatar nordbergm avatar plasma avatar ptasz3k avatar q42jaap avatar robertlyson avatar romanx avatar russcam avatar stevejgordon avatar szabosteve avatar tasteful avatar tkirill avatar udiben avatar yohdeadfall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elasticsearch-net's Issues

Exception thrown when ElasticClient.GetMapping<T>() called for class which hasn't been mapped.

I needed the functionality to check if mapping exists for some class. ElasticClient.GetMapping() was used but exception is thrown when mapping doesn't exist.

It is here: \src\Nest\ElasticClient-MappingType.cs -> GetMapping(string index, string type)
the line:
var mappings = JsonConvert.DeserializeObject<IDictionary<string, TypeMapping>>(status.Result, SerializationSettings);
throws deserialization exception.

I would like to see say the following:

  1. GetMapping returns null if no mapping exists.
  2. to have bool TryGetMapping(ref TypeMapping) method.

I would be happy to help the project by implementing this and send you patch if you are OK with it.
Thanks!

Using custom analyzers or token filters to retrieve fields

Hello,
I am indexing tags such as Java, C++, C#, elastic-search, etc. When I enter a tag name, I need to check if it already exists. I want this operation to be case insensitive, so if I type c++ and there is a document with name C++ I want to get the existing document. To do so, I am using a text query:

return GetClient().Search(s => s
.Query(q => q
.Text(t => t
.OnField("name")
.QueryString(tagName.ToLower())
)
)
).Documents.SingleOrDefault();

But this ignores the special characters, and I get an exception when I search for C++, for example (it returns me c, C#, C++, C$, and so on).

I tried to use the TextQueryDescriptor.Analyzer() but it accepts a string as a parameter, so I tried the existing analyzers from elastic search such as "simple", "whitespace", "keyword" and "not_analyzed" but none of them worked. Some of them returned all tags starting with C, ignoring special characters, and others didn't return anything.

I don't know a lot about Analyzers, Tokenizers and Token Filters, but I believe there is a way of combining them to get what I need, that is a text query that is case insensitive but that doesn't ignore special characters. I don't know if this qualifies as an issue and I am sorry to open so many issues in the last days, but if there is a way of performing such query using NEST I would really appreciate if someone told me how.

Thanks in advance.

Index with id

Hi,
I'd prefer to Index objects with a pre-set id. As I understand it, the method of doing this would be to call

Index(T object, string index, string type, [int|string] id)

If possible, I would like to not have to specify index and type, like "Index(T object, string id)", but of course that'l have the same footprint as Index(T object, string index).

Should there be another method for this, or should Client.Settings.DefaultIndex and Client.InferTypeName() be made public?

Thanks!

Any way to specify multiple queries?

I expected this to work, but it doesn't. I am not seeing any way to specify multiple queries or filters with the DSL?

     var results = ElasticClient.Search<Deal>(body => body
            .Query(query => query.ConstantScore(
                cs => cs.Filter(filter => filter.Term(x => x.TeamId, "3"))))
            .Query(query => query.ConstantScore(
                cs => cs.Filter(filter => filter.Terms(x => x.Years, new string[] { "2011", "2012"}))))
            .Take(10));

Am I doing something wrong or is this not supported? I see the Operator.And enum, but I don't understand how to combine them into 1 statement.

MapperParsingException - Trying to Parse Non-DateTime Props

Hello,
Getting this error when trying to index a .net class with a property :
public string ProductId { get; set; }

If its value is "01-685", I get the error below.
How do I tell it to look at this property as a String not a DateTime?

Weird thing is I have a another class with the same values for a string and that works fine; I'm confused.

{"error":"MapperParsingException[Failed to parse [productId]]; nested: MapperParsingException[failed to parse date field [01-685], tried both date format [dateOptionalTime], and timestamp number]; nested: IllegalFieldValueException[Cannot parse "01-685": Value 685 for dayOfYear must be in the range [1,365]]; ","status":400}

Thanks

IElasticClient

It would be great if NEST's ElasticClient implemented an interface (IElasticClient). This would allow easier mocking for unit tests (i.e. I could mock IElasticClient and then assert that methods were called on it without having to actually impact the real elasticsearch data store).

I have implemented this manually using IElasticSearchWrapper (with a default implementation that just calls the same methods on an ElasticSearch instance) but it would be even better if this worked OOTB.

DeleteById will delete index if id parameter is null

The ElasticClient.DeleteById(string index, string type, string id) overload will delete the entire index if id happens to be null.

I'm not sure if this is desired behavior or not, but it might be nice to have a ThrowIfNull inside the method.

I'm using NEST in a windows service and saw my whole index of 190k documents wiped out because of a data bug on my part.

Yes, I should have checked for a null id value before calling the method. I admit it. :) But I was a bit surprised that NEST just deleted the whole index because of my oversight.

I love the product. Keep up the great work.

Depreciation of SearchRaw & QueryRawJson() means you can't use Factory DSL

Sorry, I should have spotted this one sooner (and maybe I've missed something) but if I create a query using the Factory DSL

var sb = SearchBuilder.Builder(); sb.Query(QueryFactory.IdsQuery(id.ToString())); sb.Filter(FilterFactory.LimitFilter(1));

.. there is no way to execute it as ..

_client.SearchRaw<ItemDto>(sb.ToString()); is depreciated ..

and

_client.Search(t => t.QueryRawJson(sb.ToString())); is also depreciated.

I'm sure in the past you could put a string into

_client.Search(t => t.Query(sb.ToString())); .. has this been removed / revised ?

.NET 3.5 compliance?

Hi,

is it possible to create a build profile that is creating NEST as a .Net 3.5 compliant DLL?
We need .Net 3.5 because we like to use NEST in a SharePoint environment and these is only 3.5 compliant.
A manuel change in the solution to .Net 3.5 wasn't succesfully.
Thx Thomas

Readme links

Some links in the readme file (indexing, searching and deleting) do not point to right content but instead to Create New Page in wiki.

Get<T> doesn't use DeserializerSettings

ElasticClient-Get.cs:60

return JsonConvert.DeserializeObject<T>(source.ToString());

ElasticClient-Get.cs:112

return JsonConvert.DeserializeObject<MultiHit<T>>(source.ToString());

Had no time to make a pull request, let's look into this tomorrow

Cannot pass dynamic into Search<T>

When passing a dynamic as the object type the client does a request for /[defaultindex]/objects/_search which always returns nothing.

Make ElasticClient mockable

I would like IElasticClient to return responses through interfaces, rather than un-mockable response types. Search could return IQueryResponse rather than QueryResponse and so on. I would like to send you a pull request with this change if you like, but I wont do it, if you think it is a bad idea :)

Objects store with a mixed case type name and search expects all lower plural

Specifically the code in ElasticClient-Search.cs in the Search function

                     var search = new SearchDescriptor<T>();
        var descriptor = searcher(search);

        var query = ElasticClient.Serialize(descriptor);
        var path = this.GetPathForTyped(descriptor);
        ConnectionStatus status = this.Connection.PostSync(path, query);
        var r = this.ToParsedResponse<QueryResponse<T>>(status);
        return r;

the call to get path for typed returns a lowercased type name that is plural when using an index other than the default

So an index of Index results in an invalid search index path of localhost:9200//index1/testobject/_search instead of the correct path of localhost:9200/index1/testobject/_search

the following code commented out results in a workable solution

in the elasticclient-inferno for comment out the lines below NOTE

function infertypename ()
{
var type = typeof(T);
var typeName = type.Name;
var att = PropertyNameResolver.GetElasticPropertyFor();
if (att != null && !att.Name.IsNullOrEmpty())
typeName = att.Name;
else
{
if (this.Settings.TypeNameInferrer != null)
typeName = this.Settings.TypeNameInferrer(typeName);
//NOTE: storage for types outside of default index result in an incorrect name
//if (this.Settings.TypeNameInferrer == null || string.IsNullOrEmpty(typeName))
// typeName = Inflector.MakePlural(type.Name).ToLower();
}
return typeName;

}

No way to filter on sub-objects for QueryDescriptor<T>

If I have an object graph of something like:

Deal ->
    Proposals ->
          Id
          Name
          Years ->
               Quarters

And I want to filter on all proposals with an Id of 2 & 5, I don't see a way to do that. Would it work to do something like:
body => body.Filter(f => f.Terms(t => t.Proposals[0].Id, [2,5]))?

Date Range Query

The documentation states the date can be in the yyyy/MM/DD hh:MM:ss format. I have only had success using the W3C time format.
I use this to convert:
time.ToString("yyyy-MM-ddTHH:mm:ss")

SearchDescriptor.Fields should (optionally) take a list of field names.

I'm currently doing a very simple search with nest, but I need to limit the fields being returned. I'm declaring my search as follows:

    SearchDescriptor<dynamic> search = new SearchDescriptor<dynamic>();

This works perfectly for my needs (as making models for our returns is a big maintenance concern), however, trying to specify Fields is almost impossible to do. I've managed to get it to work by doing this:

    search.Fields(f => (new { listing_name = "" }).listing_name);

This is very difficult to work with, and while I understand that if I wasn't using dynamic this would be more straightforward, I believe the simplest solution would be to have Fields optionally take a list of field names. It's straightforward, and is the 'least surprising' way of working with the Fields parameter (imho).

MapperParsingException on Bulk Index

I'm trying to index about 500,000 items using the Index(IEnumerable) method, and get that exception with a message of Malformed content, must start with an object. I tried setting the SetMaximumAsyncConnections to 20 as in the docs, but that didn't help. If I just use the non-enumerable version, it all indexes fine though, just takes a very long time.

Null reference exception at IdResolver class

I am getting a null reference exception at IdResolver.cs, line 44. The static object MakeDelegateMethodInfo of class MethodInfo is null at method GetIdFor(T @object). It happens when I try to index a document.
Perhaps I have some mistake in my code, or there is something wrong with my connection, but since I've just updated to version 0.9.5.0 I thought someone could check if the problem is in the new version. Even if the problem is not in NEST, I would like some advice to find out why this is happening.
Thanks in advance.

How to combine query_string and terms query

Hi,

I'm working on a sample ASP.NET MVC application based on NEST and have some difficulties to correctly build a query.

My code:

    var search = new SearchDescriptor<Product>()
                                     .FacetTerm(t => t
                                         .OnField(f => f.CategoryId)
                                         .Size(20));

If there is nothing in the search box I use:

search.Query(q => q.MatchAll());

If there is something I use:

search.Query(q => q.QueryString(qs => qs.Query(parameters.FreeText).Operator(Operator.and)));

Additionaly at some point I have following facet definition:

search.FacetTermsStats(f => f
                        .KeyField("parameters.id")
                        .ValueField("parameters.id"));
QueryResponse<Product> results = client.Search<Product>(s => search);
var products = results.Documents.ToList();

All works fine till now.

I'd like now to click on one of the parameters facets and I would like to combine the search box query and the selected faced query. The results I should get should be only that documents matching free text query and selected parameter id.

Could you advice me please how to construct a query to get correct results?

That is the first part of the question :)

Let's say we have more FacetTermsStats: fields.id, colours.id and so on - how could I dynamically attach a boolean query to the SearchDescriptor?

Mapping here: https://gist.github.com/2988792

Sample product here: https://gist.github.com/2988837

Thanks!
Marek

Btw: Are you interested in publishing a sample application? I can do it - I could publish it when I finish it. the only thing I'm not sure is what db and data access to use...? At the moment I'm working with NHibernate, StructureMap as IoC and MS SQL Express. Let me know if you have any other preferences.

Thread safety

This is more of a question rather than an issue.

If I instantiate a single ElasticClient and use it from multiple threads (without altering ConnectionSettings), should I expect the object to work correctly?

The methods I call from one thread (the 'writer') are:

public bool IsValid { get; }
public ConnectionStatus Index(IEnumerable objects) where T : class;

And from the other (the 'reader') are:

public bool IsValid { get; }
public QueryResponse Search(string search, string index, string typeName) where T : class;

Looking at the NEST code, I think this is safe. Is this safe, or would I be best to instantiate separate reader and writer clients?

Hightlight and fuzzy query?

Hi,

public class Post{
    public string Title{get;set;}
    ...
}

I want to create a fuzzy query and highlight title on results.

A post titled "This is a test title"

and query string is "is"

so the expected result is

"This is a test title"
.

Thanks.

Lowercasing Search / Sort terms

Sorry to keep bugging you with this small stuff!

When I run queries it keeps lowercasing the terms in the sort and term functions. Unfortunately our elasticsearch index uses fields with all CAPs. "MID" for example.

NEST is turning my searches into:

{
  "query": {
    "bool": {
      "must": [
        {
          "constant_score": {
            "filter": {
              "term": {
                "mID": "messageidyay"
              }
            }
          }
        },
        {
          "constant_score": {
            "filter": {
              "term": {
                "sID": "2"                  
              }
            }
          }
        }
      ]
    }
  }
}

Which causes the search on SID and MID to fail.

My search is constructed as such

        var results = client.Search<DeliveryEvent>(s => s
                                                                                .SortDescending(f => f.RA)
                                                                                .Query(query => query
                                                                                .Bool(bq => bq
                                                                                .Must(
                                                                                mq => mq.ConstantScore(cs => cs.Filter(filter => filter.Term(x => x.MID, "meesageid"))),
                                                                                mp => mp.ConstantScore(cs => cs.Filter(filter => filter.Term(x => x.SID, "serverid"))))))

and that DeliveryEvent class sets up properties like this

    [ElasticProperty(Name = "MID")]
    public string MID { get; set; }

to map the names to upper case. I'm sure I'm missing something but I'd appreciate a pointer.

Thanks again!!!!

Index not being created?

I have a custom mapping and I'm trying to force deletion and recreation of the index, I have the following code (using the latest NEST from NuGet)

TypeMapping mapping = new ActivityLogIndexMap().Map();
client.DeleteMapping();
client.Map(mapping);
client.Refresh();

Unfortunately this does not create the mapping in Elastic Search :-/

Have to lowercase in query though standard analyzers used both for index and search.

Hi,
Thank you for your work, Martijn!
I'm not sure it's not the issue but that doesn't make sense for me, can you please explain:
I am using standard analyzers for both index and search.
User with first name "John" is added to index.
when running this search:

var results = Client.Search(s => s
.From(0)
.Size(10)
.Fields(f => f.Id, f => f.FirstName)
.Query(q => q
.Term(t => t.FirstName, "John")
)
);
no document is found. I have to lowercase to "john" to get expected result.
Can you please explain why standard analyzer doesn't lowercase search queries but lowercase when indexing? I looked at source code of NEST and it doesn't look like a bug.

Is Thrift transport supported?

I see the project in the solution, but I don't see any real public types that it uses or any project references to the Thrift one.

Mapping non generic

I'm creating my mappings by iterating through all [ElasticType] classes, and mapping them with Map().
However to do that, I need to call Map() with reflection.

Any chance you could add Map(Type t) ?

Searching by Multiple Terms

Is it possible to search using multiple terms with an AND clause? Having some trouble sorting that with the fluent interface. For instance I have a search query like this but it's definitely not correct. I'd like to add more terms to the query but can't figure out how to structure the query. Thanks for any help!

var results = client.Search(s => s
.From(query.PageStart)
.Size(query.PageSize)
.SortDescending(f => f.RA)
.Query(q=>q.Term(f=>f.MID, "messageid"))
.Query(q=>q.Term(f=>f.SID, 5))
.Query(q=>q.Term(f=>f.TY, 2))
.Query(q=>q.Term(f=>f.BT, 1))
)

SortGeoDistance

I am trying to replicate the following sort object via the NEST library:

"sort": {
"_geo_distance": {
"order": "asc",
"position": {
"lat": 51.399891,
"lon": -3.273926
},
"unit": "km"
}
}

search.SortGeoDistance(sgd => sgd.OnField("position").PinTo(Convert.ToDouble(geoFilter.lat1), Convert.ToDouble(geoFilter.lng1)).Unit(unit).Ascending());

yields:

"sort": {
"position": {
"order": "asc",
"pin.location": "51.48, 3.18",
"unit": "km"
}
}

Any suggestions?

Text Phrase Prefix function generates incorrect JSON

It appears incorrect JSON is being generated when constructing a Text Phrase Prefix query. Currently the JSON generated is something like (note the incorrect type):

{
  "query": {
    "text": {
      "name": {
        "type": "text_phrase_prefix",
        "query": "harry p",
        "operator": "and"
      }
    }
  }
}

Instead it should be (with the correct type)

{
  "query": {
    "text": {
      "name": {
        "type": "phrase_prefix",
        "query": "harry p",
        "operator": "and"
      }
    }
  }
}

Or

{
    "query": {
        "text_phrase_prefix" : {
            "name" : {
                "query" : "harry p",
                "operator" : "and"
            }
        }
    }
}

How do I dynamically create multiple filters on one search query?

I need to build my query dynamically and I'm trying to add multiple filters when needed. If I try the following:

var searchquery = new SearchDescriptor<Part>();
searchquery = searchquery.Filter(filter => filter.Term(x => x.DivisionId, divId));
searchquery = searchquery.Filter(filter => filter.Term(x => x.ProductId, productId));

the second filter replaces the first instead of adding to it.

I see how multiple queries are created from the unit tests, but I'm not sure how I can add them only as needed. Sometimes there may be 2 filters, sometimes 3, and sometimes none.

Slower response using fuid API

I am seeing slower response times using the fluid API vs json.

For example:

this returns in 180 ms:
var json = @"{""from"" : 10000, ""size"" : 1000,{""query"" : { ""match_all"" : { }}}}";
var searchResp = client.SearchRaw(json );

this returns in 6100 ms:
var searchResp = client.Search(s => s.MatchAll().From(10000).Size(1000));

Let me know if I constructed the query incorrectly using the API.

thanks,
mark

Specific fields and routing on Get and Multi Get

Hi,
Does NEST allow me to specify the fields to be retrieved in cases that I only need one or two fields in documents with a lot of other information?
In elasticsearch you can do something like:

curl -XGET 'http://localhost:9200/twitter/tweet/1?fields=title,content'

and

curl 'localhost:9200/_mget' -d '{
"docs" : [
        {
            "_index" : "test",
            "_type" : "type",
            "_id" : "1",
            "fields" : ["field1", "field2"]
        }
    ]
}'

It would be also good to allow me to provide the routing value:

curl -XGET 'http://localhost:9200/twitter/tweet/1?routing=kimchy'

How to specify index 'type' on Search()?

Hi,
In the add to index there is a way to say what index and what type to use;

this.ElasticClient.IndexAsync(data, this._index, this._indexType, null);

However it appears in the search there is no way to indicate what "type" to use, its infered off the generic?

var queryResults = this.ElasticClient.Search<IndexData>(query);

As in that looks for a "indexdatas" type, not the "type" given in the Index method above.

How would one set the type to use for a search? Thanks!

ElasticClient as Singleton?

Hi,

I'm giving a try to NEST for few last days. It's amazing, thanks.

I'm using StructureMap in my web app and I'm not sure if the best practice is to set ElasticClient instance as Singleton.

Not sure if Github issues are the best place for such questions. If not please let me know what is your prefered way.

Thanks,
Marek

Connecting a host without providing port information.

Hi There,

I know it feels odd when reading header but let me tell my case,

Currently I'm developing a saas based ElasticSearch and i want to use Nest as .NET client both for individual or as a plugin from appharbor.

Simply we are creating urls with api-key information like;

http://api.searchbox.io/api-key/yoursupersecretapikey/your-index ... etc.

Whenever i create a ConnectionSettings instance with provided constructors (consider with port 80), flow comes to below method inside Connection which creates url with with ":" and it results like
"http://api.searchbox.io/api-key/12313123123:80" and it fails to connect.

private string _CreateUriString(string path)
{
 var s = this._ConnectionSettings;
 if (!path.StartsWith("/"))
 path = "/" + path;
 return string.Format("http://{0}:{1}{2}", s.Host, s.Port, path);
}

Is it possible to create a constructor without port number information and also if we set null or 0 value for port information, then above CreateUriString method can create urls without appending port numbers and colon ?

I would like to throw a pull request if this solution ok with you as well.

KR,
Ferhat Sobay.

Group by?

Hi,
I have to display the number of search results counted by one or more fields. just like group by in T-SQL
Thanks.

Creating geo_point type?

Hi, need to do some geospatial queries and it appears I need to set my mapping on fields to be field type "geo_point". I see how its done via curl from this (https://gist.github.com/1050346) pages example;

Create proper mapping

curl -XPUT 'http://localhost:9200/pins/pin/_mapping' -d '
{
"pin" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}'

I have some classes setup like this;
public class IndexData
{
public string Id { get; set; }
public Dictionary<string,object> Data { get; set; }
public Location Location { get; set; }
}

public class Location
{
    public float lat { get; set; }
    public float lon { get; set; }
}

Then I setup and try to index like this;
var elasticSettings = new ConnectionSettings(this.ConnectionString, 9200).SetDefaultIndex("listings").SetMaximumAsyncConnections(20);
this.ElasticClient = new ElasticClient(elasticSettings);
this.ElasticClient.IndexAsync(data, "listings", "listing", null);

Problem is the lat/lon types on the Location are of double;
location: {
dynamic: true
properties: {
lon: {
type: double
}
lat: {
type: double
}
}
}

Thanks for pointing me straight, I assume I am just doing something wrong.

Regards,
Steven

Breaking change: Async operations return Task<ConnectionStatus>

In older versions of NEST async operations followed the following pattern

void OperationAsync(params...., Action<ConnectionStatus> callback);

This is pretty much a relic of when I first started stubbing NEST back in 2010 and I've been meaning to convert it to a task based async call ever since

The first official release for NEST (0.9) will follow a different pattern:

Task<ConnectionStatus> OperationAsync(params);

types should not be pluralized

in all of my scenario's it seems counter-intuitive to pluralize type names. I can understand for indexes as they are collections of different types but not for a type itself.

NuGet Package

Hi Mpdreamz,

Could you please deploy NEST to nuget repository ?

KR,
Ferhat.

Not_analyzed has no effect

I'm trying to tell ElasticSearch to stop analyzing a certain property, to prevent values with a dash from being split. I tried the options I could find, but none of them work. Have I stumbled upon a bug in NEST or am I doing something wrong? Let me tell you what I've tried so far.

Mapping with ElasticProperty

The NEST docs tell me I can use the ElasticProperty attribute with a FieldIndexOption.

[ElasticType( Name = "product" )]
public class ElasticSearchProduct
{
    [ElasticProperty( OmitNorms = true, Index = FieldIndexOption.not_analyzed )]
    public string Format { get; set; }
}

When the Index method has been called, I can see the product has been correctly indexed and the mapping is created in ElasticSearch. However, when I perform a faceted search, the value is still split. (The facet value "E-book" becomes two: "E" and "Book".)

Manually call the mapper method

I found issue #19 that told me to persist the mapping, so I did:

this.ElasticSearch.Map<ElasticSearchProduct>( "products" );

It creates a mapping, but the value is still split.

Explicit type mapping

Then I tried to perform an explicit type mapping, as mentioned in issue #19.

var notAnalyzedProperty = new TypeMappingProperty
{
    Type = "string",
    Index = "not_analyzed"
};
var newMapping = new TypeMapping( "product" );
newMapping.Properties.Add( "format", notAnalyzedProperty );
this.ElasticSearch.Map( newMapping, index );

That doesn't prevent the value from being split either.

I'm running this with:

  • the latest NEST package from NuGet: 0.9.1.0
  • the latest ElasticSearch 0.19.7, with default configuration.
  • search queries that use an index alias and a routing value, a construct that I've found on the ElasticSearch Google group. That should have nothing to do with this issue, but perhaps it's good to know to determine the cause.

If you need me further to debug this or provide any more information, just let me know.

StackOverflow exception in FacetConverter class

Hello, I've just downloaded the latest head revision and updated the Nest.dll in my project, and suddenly my FacetTerm Search stopped working. I have a method that is like:

return GetClient().Search(s => s
.FacetTerm(t => t
.FacetFilter(f => f.Term(t => t.User, userId))
.Order(TermsOrder.count)
.OnField(p => p.TagIds)
.Size(10)
));

and I am getting this message: 'An unhandled exception of type 'System.StackOverflowException' occurred in Newtonsoft.Json.DLL'.

It seem that the method ReadJson in FacetConverter class is calling itself recursively. Any ideas?

DeleteByQuery delete all items in index

Following code delete all records in index, not only with id = "1404.0.0"

        var indexedData = new[] { "1404.0.0" };

        string query = @" { ""query"" : {
                        ""terms"" : { ""id"" : [" + string.Join(",", indexedData.Select(x => @"""" + x + @"""")) + @"] }
                } }";

       var status = client.DeleteByQuery<AddressSearch>(query);

I captured following request

DELETE http://10.54.xx.xx:9200/test_create/address_search/?pretty=true
HTTP/1.1
Accept: application/json
Content-Type: application/json
Host: 10.54.18.47:9200
Content-Length: 64
Expect: 100-continue
Connection: Keep-Alive

{ "query" : {
"terms" : { "id" : ["1404.0.0"] }
} }

On elastic search forum I got answer that
I should replace :
http://10.54.xx.xx:9200/test_create/address_search/?pretty=true
by : http://10.54.xx.xx:9200/test_create/address_search/_query?pretty=true

More info here
https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/zdKU9BiUwj0

Thanks!

Help on setting Type for methods

Hello!

I have a situation where I'm trying to figure out a way to, for example, call some methods but setting the Type dynamically or in some similar way.

I have DeleteByQuery method

client.DeleteByQuery(q => q.Term(f => f.TY, "test"));

but I will also need to do

client.DeleteByQuery(q => q.Term(f => f.TY, "test"));

This is inside a method like:

    public void DeleteBySomething(string test)
    {
        var client = new ElasticClient(elasticSettings);
        client.DeleteByQuery<ClassType1>(q => q.Term(f => f.TY, test));
    }

I'm trying to figure out a way that I could pass a type or generic into the method that would call this function so that I wouldn't have two DeleteByQuery methods. This would help keep my code more DRY but I'm having a difficult time conceptualizing how I would do this.

Thanks for any help!!! (I realize this isn'ts really an "issue" - maybe I could start and help support a google group for NEST?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.