我正在使用.NET中的NEST库进行查询。我已将一个属性映射为CurrentProductStatus(字符串)。在文档文件记录中,CurrentProductStatus如下所示: “ OldStatus |已扫描:[购买]已接收| 0 |#f6f6f6”
所以我必须使用第二个管道分隔的字符串(例如:“已扫描:[购买]已接收”)过滤结果。我已经尝试过使用标准分析仪。没有为我工作。
inline void update_dc(int new_dc) // or a macro if you want,
{ // but inline functions are more preferrable
#ifdef DEBUG_DC
if (new_dc == 1) // or if (new_dc != dc)
{
trap();
}
#endif
dc = new_dc;
}
这是我的代码的一部分,这是我查询的地方。
任何想要进行搜索和过滤的想法
答案 0 :(得分:0)
a pipeline似乎很合适,可以将CurrentProductStatus
字段中的单独字段解析出来,并将它们添加到索引的文档中。然后,您可以在这些字段上进行查询。
替代方法是定义一个分析器,该分析器以有利于您的用例的方式对输入进行标记。例如,标准分析器将通过以下方式进行标记化
GET _analyze
{
"text": ["OldStatus|Scanned: [PURCHASE] Recieved|0|#f6f6f6"]
}
---
{
"tokens": [
{
"token": "oldstatus",
"start_offset": 0,
"end_offset": 9,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "scanned",
"start_offset": 10,
"end_offset": 17,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "purchase",
"start_offset": 20,
"end_offset": 28,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "recieved",
"start_offset": 30,
"end_offset": 38,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "0",
"start_offset": 39,
"end_offset": 40,
"type": "<NUM>",
"position": 4
},
{
"token": "f6f6f6",
"start_offset": 42,
"end_offset": 48,
"type": "<ALPHANUM>",
"position": 5
}
]
}
在查询时将标准分析器应用于Scanned: [PURCHASE] Recieved
,
GET _analyze
{
"text": ["Scanned: [PURCHASE] Recieved"]
}
----
{
"tokens": [
{
"token": "scanned",
"start_offset": 0,
"end_offset": 7,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "purchase",
"start_offset": 10,
"end_offset": 18,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "recieved",
"start_offset": 20,
"end_offset": 28,
"type": "<ALPHANUM>",
"position": 2
}
]
}
三个令牌将匹配一个match
查询。