C# Elasticsearch使用ID列表筛选多重匹配
我是ES的新手,我正在尝试解决以下问题 我已使用以下配置在Elasticsearch中创建了索引:C# Elasticsearch使用ID列表筛选多重匹配,c#,
elasticsearch,nest,C#,
elasticsearch,Nest,我是ES的新手,我正在尝试解决以下问题 我已使用以下配置在Elasticsearch中创建了索引: client.Indices.Create(lineItemIndex, c => c .Settings(s => s .Setting("max_ngram_diff", 13) .Analysis(a =>
client.Indices.Create(lineItemIndex,
c => c
.Settings(s => s
.Setting("max_ngram_diff", 13)
.Analysis(a => a
.Tokenizers(tf => tf
.NGram("mynGram", td => td
.MaxGram(15).MinGram(2)))
.Analyzers(aa => aa
.Custom("mynGram_analyzer", ca => ca
.Filters(new List<string> {"lowercase"})
.Tokenizer("mynGram")))))
.Map<ElasticSearchLineItem>(m => m
.Properties(ps => ps
.Text(ss => ss
.Name(na => na.LineItemName)
.Fields(ff => ff
.Keyword(k => k
.Name("keyword"))
.Text(tx => tx
.Name("fulltext")
.Analyzer("whitespace")
.Boost(10.0))
.Text(tx => tx
.Name("partial")
.Analyzer("mynGram_analyzer")
.Boost(1.0)))))
.Properties(ps => ps
.Keyword(kw => kw
.Name(na => na.LineItemId)
.Index(false)))
.Properties(ps => ps
.Keyword(kw => kw
.Name(na => na.Id)
.Index(false)))
.Properties(ps => ps
.Text(ss => ss
.Name(na => na.LineItemNumber)
.Fields(ff => ff
.Keyword(k => k
.Name("keyword"))
.Text(tx => tx
.Name("fulltext")
.Analyzer("whitespace")
.Boost(10.0))
.Text(tx => tx
.Name("partial")
.Analyzer("mynGram_analyzer")
.Boost(1.0)))))
.Properties(ps => ps
.Keyword(ss => ss
.Name(na => na.SupplierName)
.Index(false)))
.Properties(ps => ps
.Keyword(ss => ss
.Name(na => na.Unit)
.Index(false)))
.Properties(ps => ps
.Number(ss => ss
.Name(na => na.PriceAmount)
.Type(NumberType.ScaledFloat).ScalingFactor(100)
.Index(false)))
.Properties(ps => ps
.Keyword(ss => ss
.Name(na => na.Currency)
.Index(false)))
.Properties(ps => ps
.Keyword(ss => ss
.Name(na => na.SupplierId)
.Index(false)))
.Properties(ps => ps
.Text(ss => ss
.Name(na => na.ImageUrl)
.Index(false)))
.Properties(ps => ps
.Text(ss => ss
.Name(na => na.SupplierPriceListId)
.Index(false)))));
无论request.ListOfFavorites
是否为空,此操作都不会返回任何内容。但是,如果我删除过滤器,它将正确返回结果
我想我错过了什么,或者我的点菜搞砸了。这里有人能帮忙吗
注意:我使用的是ES 7.5.1和NEST 7.5.1
编辑:
我更改了索引,并从我的supplierId字段中删除了索引(false)
以下是更新后kibana中显示的映射
{
"mapping": {
"properties": {
"currency": {
"type": "keyword",
"index": false
},
"id": {
"type": "keyword",
"index": false
},
"imageUrl": {
"type": "text",
"index": false
},
"lineItemId": {
"type": "keyword",
"index": false
},
"lineItemName": {
"type": "text",
"fields": {
"fulltext": {
"type": "text",
"boost": 10,
"analyzer": "whitespace"
},
"keyword": {
"type": "keyword"
},
"partial": {
"type": "text",
"analyzer": "mynGram_analyzer"
}
}
},
"lineItemNumber": {
"type": "text",
"fields": {
"fulltext": {
"type": "text",
"boost": 10,
"analyzer": "whitespace"
},
"keyword": {
"type": "keyword"
},
"partial": {
"type": "text",
"analyzer": "mynGram_analyzer"
}
}
},
"priceAmount": {
"type": "scaled_float",
"index": false,
"scaling_factor": 100
},
"supplierId": {
"type": "keyword"
},
"supplierName": {
"type": "keyword",
"index": false
},
"supplierPriceListId": {
"type": "text",
"index": false
},
"unit": {
"type": "keyword",
"index": false
}
}
}
}
在映射过程中,您指定了供应商ID,因此无法在其上搜索
.Properties(ps => ps
.Keyword(ss => ss
.Name(na => na.SupplierId)
.Index(false)))
此外,您不需要为字段指定后缀,因为它没有定义为多字段,所以非常简单
.Filter(f => f
.Terms(t => t
.Verbatim()
.Field(p => p.SupplierId)
.Terms(request.ListOfFavorites.ToArray())))));
够了
希望能有所帮助。谢谢你的建议。不幸的是,删除“索引(false)”并没有任何帮助。在更改后,您可以从elasticsearch共享索引映射吗?在删除索引(false)后,我进行了一次编辑,显示了映射。现在它似乎返回结果:)现在我只需要在我的ES中获取更多供应商ID,看看过滤是否有效。不过有一个小问题。如果ID数组为空,则不返回任何内容。你有什么建议吗?
.Filter(f => f
.Terms(t => t
.Verbatim()
.Field(p => p.SupplierId)
.Terms(request.ListOfFavorites.ToArray())))));