2014-12-05 50 views
2

我有一个问题,得到一个非常简单的ElasticLinq搜索来返回结果。问题似乎是它将一个URL发送到ElasticSearch,对于搜索URL是不正确的。以下是我已经试过:ElasticLinq似乎没有使用正确的URL

var connection = new ElasticConnection(new Uri("http://localhost:9200"), index: "mytypes"); 
var context = new ElasticContext(connection); 
var results = (from a in context.Query<MyType>() select a).Take(10).ToArray(); 

当我执行最后一行,这里是我的小提琴手看到的网址:

http://localhost:9200/mytypes/mytypes/_search 

这个问题似乎是mytypes在使用了两次网址而不只是一次。

我也试过不提供一个默认指数为ElasticConnection构造,在这种情况下,搜索网址如下:

http://localhost:9200/_all/mytypes/_search 

在这两种情况下,我没有得到任何结果回来。如果我提交查询使用

http://localhost:9200/mytypes/_search 

我得到的结果回来。

任何想法如何让ElasticLINQ使用正确的搜索URL?

回答

2

URL中的第二mytypes是从查询的强T型()

有一个缺省惯例,一个CLR类型等效于一个Elasticsearch文档类型。如果您不希望这样做,则可以改写ElasticMapping的GetDocumentType以返回空字符串或空字符串。

然后你会想要考虑这些类型是如何映射的。还有其他一些选项,例如完全限定字段名称并在每个字段中插入字段存在检查。 (这是我们在这里做的)

public JohnsElasticMapping : ElasticMapping { public string GetDocumentType(Type type) { return null; } } ... var context = new ElasticContext(connection, new JohnsElasticMapping());