当我像这样索引新文档时:
ElasticClient.Index(product, idx => idx.Index(indexName));
并且我尝试在此字段(这是一个500个字符的文本)上进行搜索/查询,但没有结果。我想搜索类似“687920/1”的内容,该内容为这500个字符。
最佳答案
下面的Elasticsearch示例可能有用
删除pdm索引
DELETE pdm
索引映射
PUT /pdm
{
"settings":{
"analysis":{
"analyzer":{
"keyword_lowercase_analyzer": {
"type": "custom",
"filter": ["lowercase"],
"tokenizer": "keyword"
}
}
}
},
"mappings": {
"product": {
"properties": {
"product_desc": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"analyzer": "keyword_lowercase_analyzer"
},
"english": {
"type": "text",
"analyzer": "english"
}
}
}
}
}
}
}
索引文档
POST /pdm/product/_bulk
{ "index": { "_id": "111" }}
{ "product_desc": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 687920/1 It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."}
{ "index": { "_id": "112" }}
{ "product_desc": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 6879210/1 It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."}
搜索查询
POST /pdm/_search
{
"query": {
"match_phrase": {
"product_desc": "687920/1"
}
}
}
关于elasticsearch - 如何使用NEST搜索文本字段 “as is”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49852421/