C#Elasticsearch-NEST逃脱WhiteSpace角色

时间:2015-09-13 11:47:18

标签: .net elasticsearch nest

我想在querystring中转义空格字符。 我的代码是

        var node = new Uri("http://localhost:9200");
        const string indexName = "evaluationdev5";
        var settings = new ConnectionSettings(
            node,
            defaultIndex: indexName
        );

        var client = new ElasticClient(settings);

        var indexExist = client.IndexExists(indexName);
        if (!indexExist.Exists)
        {
            var response = client.CreateIndex(indexName);
        }
        var person = new Person
        {
            Id = "1",
            Firstname = "john smith",
            Lastname = "hendrick"
        };
        var person2 = new Person
        {
            Id = "2",
            Firstname = "smith john",
            Lastname = "hendrick"
        };
        client.Index(person, x => x.Index(indexName));
        client.Index(person2, x => x.Index(indexName));
        var result = client.Search<Person>(s => s
            .Explain()
            .From(0)
            .Size(10)
            .Query(q => q
                .QueryString(qs => qs
                    .OnFields(new[]{"firstname","lastname"})
                    .Query(@"joh*\ smith")
                    .DefaultOperator(Operator.And)
                )
            )
        );

人类是

public class Person
{
    public string Id { get; set; }
    public string Firstname { get; set; }
    public string Lastname { get; set; }
}

我的查询字符串是 joh * \ smith 。我想只得到“约翰史密斯”。但结果是空的。 另外我尝试使用引号查询字符串“joh * smith”仍然结果为空。 我能做什么这个查询?

0 个答案:

没有答案