elasticsearch,nest,shingles,C#,elasticsearch,Nest,Shingles" /> elasticsearch,nest,shingles,C#,elasticsearch,Nest,Shingles" />

C# Elasticsearch 2.x-返回木瓦列表

C# Elasticsearch 2.x-返回木瓦列表,c#,elasticsearch,nest,shingles,C#,elasticsearch,Nest,Shingles,我有一个字段“searchtext”,我提供了一个子字段“shingle”,我用一个shingles过滤器为searchtext字段编制索引 我需要得到为该区域创建的木瓦列表,以便我可以在该区域上执行一些操作。当我检索“searchtext.shingle”字段时,它只包含原始文本 这是否意味着我设置的木瓦分析器不工作,或者我需要以不同的方式获取木瓦列表 您可以使用如下方法检索“木瓦”字段的所有术语: curl -XGET 'http://localhost:9200/your_index/yo

我有一个字段“searchtext”,我提供了一个子字段“shingle”,我用一个shingles过滤器为searchtext字段编制索引

我需要得到为该区域创建的木瓦列表,以便我可以在该区域上执行一些操作。当我检索“searchtext.shingle”字段时,它只包含原始文本


这是否意味着我设置的木瓦分析器不工作,或者我需要以不同的方式获取木瓦列表

您可以使用如下方法检索“木瓦”字段的所有术语:

curl -XGET 'http://localhost:9200/your_index/your_type/1/_termvectors?pretty=true' -d '{
  "fields" : ["searchtext.shingle"],
  "offsets" : true,
  "payloads" : true,
  "positions" : true,
  "term_statistics" : true,
  "field_statistics" : true
}'

除了Val的回答之外,您还可以使用AnalyzeAPI测试分析器的工作方式。例如,让我们构建一个自定义分析器,然后测试它为给定输入生成的令牌

var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var defaultIndex = "analyzer-test";
var connectionSettings = new ConnectionSettings(pool)
        .DefaultIndex(defaultIndex);

var client = new ElasticClient(connectionSettings);

if (client.IndexExists(defaultIndex).Exists)
    client.DeleteIndex(defaultIndex);

client.CreateIndex(defaultIndex, c => c
    .Settings(s => s
        .Analysis(a => a
            .TokenFilters(tf => tf
                .Shingle("my_shingle", sh => sh
                    .MaxShingleSize(3)
                    .OutputUnigrams()
                )
            )
            .Analyzers(an => an
                .Custom("my_shingle_analyzer", sa => sa
                    .Tokenizer("standard")
                    .Filters("lowercase", "my_shingle")
                )
            )
        )
    )
);
现在来测试一下

var analysisResponse = client.Analyze(a => a
    .Index(defaultIndex)
    .Analyzer("my_shingle_analyzer")
    .Text("This is the text I want to analyze")
);

foreach (var token in analysisResponse.Tokens)
{
    Console.WriteLine($"{token.Token}");
}
发出以下标记

this
this is
this is the
is
is the
is the text
the
the text
the text i
text
text i
text i want
i
i want
i want to
want
want to
want to analyze
to
to analyze
analyze

提供了一个子字段“shingle”
您是指在映射中还是在实际的json文档中?如果是前者,您首先如何检索searchtext.shingle字段?我有一个映射到一个名为“searchtext”的属性,在映射中,我创建了一个映射到“searchtext.shingle”,以便可以显式检索创建的shingle。我通常使用到文档类的映射,但是这个映射并不直接存在,因为该字段只是由我创建的映射创建的。我想自己使用字段来检索特定的数据字段,而不是使用文档映射,因为随着返回的数据量的增加,文档映射可能会变得非常庞大。这方面有什么进展吗?嗨,谢谢你的评论。这正是我所需要的。太棒了,很高兴它有帮助!不过,如果答案对你有帮助的话,尽管接受吧。谢谢。我直接使用JSON测试了分析器,但考虑了.NET代码!