我有我想要索引的postgres数组列,然后在搜索中使用它。下面是示例,
电话= "+175 (2) 123-25-32","123456789",“+12111-111-11”
我已经使用analyze api分析了标记,elasticsearch将该字段标记为多个字段,如下所示
curl -XGET 'localhost:9200/_analyze' -d '
{
"analyzer" : "standard",
"text" : [ "+175 (2) 123-25-32", "123456789", "+12 111-111-11" ]
}'
{
"tokens": [
{
"token": "analyzer",
"start_offset": 6,
"end_offset": 14,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "standard",
"start_offset": 19,
"end_offset": 27,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "text",
"start_offset": 33,
"end_offset": 37,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "175",
"start_offset": 45,
"end_offset": 48,
"type": "<NUM>",
"position": 4
},
{
"token": "2",
"start_offset": 50,
"end_offset": 51,
"type": "<NUM>",
"position": 5
},
{
"token": "123",
"start_offset": 53,
"end_offset": 56,
"type": "<NUM>",
"position": 6
},
{
"token": "25",
"start_offset": 57,
"end_offset": 59,
"type": "<NUM>",
"position": 7
},
{
"token": "32",
"start_offset": 60,
"end_offset": 62,
"type": "<NUM>",
"position": 8
},
{
"token": "123456789",
"start_offset": 66,
"end_offset": 75,
"type": "<NUM>",
"position": 9
},
{
"token": "12",
"start_offset": 80,
"end_offset": 82,
"type": "<NUM>",
"position": 10
},
{
"token": "111",
"start_offset": 83,
"end_offset": 86,
"type": "<NUM>",
"position": 11
},
{
"token": "111",
"start_offset": 87,
"end_offset": 90,
"type": "<NUM>",
"position": 12
},
{
"token": "11",
"start_offset": 91,
"end_offset": 93,
"type": "<NUM>",
"position": 13
}
]
}我希望elasticsearch要么不做标记化,要么存储没有特殊字符的数字,例如"+175 (2) 123-25-32“转换为"+17521232532”,或者简单地对数字进行索引,以便在搜索结果中可用。
我的映射如下:
{ :id => { :type => "string"}, :secondary_phones => { :type => "string" } }下面是我尝试执行查询的方法
settings = {
query: {
filtered: {
filter: {
bool: {
should: [
{ terms: { phones: [ "+175 (2) 123-25-32", "123456789", "+12 111-111-11" ] } },
]
}
}
}
},
size: 100,
}附注:我也尝试过删除特殊字符,但没有成功。
我相信这是可以实现的,我错过了一些东西。请给我一些建议。
谢谢。
发布于 2016-02-16 11:14:05
如果只想对数据执行精确匹配,就像在terms查询示例中一样,最好的方法是将映射中的index映射参数设置为not_analyzed。看一看documentation here。
这将完全禁用对值的分析(或标记化),并将字段内容(数组中的每一项)视为单个标记/关键字。
https://stackoverflow.com/questions/35422907
复制相似问题