作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用ElasticSearch(和Rails),我尝试使用连字符作为分隔符,对包含mac地址的字段建立索引并执行搜索查询,但未成功:
24-A4-3C-02-37-26
Box.search(q: "24-A4-3C-02-37-26").results.map(&:macaddress)
["24-A4-3C-02-37-xx", "DC-9F-DB-F6-B2-xx", "C4-10-8A-13-53-xx", "C4-10-8A-13-54-xx", "C4-10-8A-13-52-xx"]
["DC-9F-DB-F6-B2-xx", "C4-10-8A-13-53-xx", "C4-10-8A-13-52-xx"]
curl "localhost:9205/boxes/_analyze?analyzer=ngram_analyzer&pretty=true" -d "24-A4-3C-02-37-26"
{
"tokens" : [ {
"token" : "24",
"start_offset" : 0,
"end_offset" : 2,
"type" : "word",
"position" : 1
}, {
"token" : "24-",
"start_offset" : 0,
"end_offset" : 3,
"type" : "word",
"position" : 2
}, {
"token" : "24-A",
"start_offset" : 0,
"end_offset" : 4,
"type" : "word",
"position" : 3
}, {
.........
@search_definition[:query] = {
multi_match: {
query: options[:q],
fields: [
"macaddress.ngram",
"macaddress.sortable^5",
...
settings analysis: {
analyzer: {
ngram_analyzer: {
type: 'custom',
tokenizer: 'my_tokenizer',
}
},
tokenizer: {
my_tokenizer: {
type: "edgeNGram",
min_gram: 2,
max_gram: 17,
# token_chars: [ "letter", "digit" ]
}
}
} do
mapping do
indexes :macaddress, type: 'multi_field', fields: {
raw: { type: "string" },
sortable: { type: "string", index: "not_analyzed" },
ngram: { type: "string", index_analyzer: :ngram_analyzer } #, search_analyzer: 'keyword' }
}
end
end
最佳答案
我已验证以下设置:
PUT test
{
"settings" : {
"analysis" : {
"analyzer" : {
"ngram_analyzer" : {
"type": "custom",
"tokenizer" : "my_tokenizer"
}
},
"tokenizer" : {
"my_tokenizer" : {
"type" : "edgeNGram",
"min_gram" : "2",
"max_gram" : "17"
}
}
}
},
"mappings": {
"boxes":{
"properties": {
"macaddress":{
"type": "multi_field",
"fields": {
"raw":{
"type": "string"
},
"sortable":{
"type": "string",
"index": "not_analyzed"
},
"ngram":{
"type": "string",
"index_analyzer": "ngram_analyzer"
}
}
}
}
}
}
}
PUT test/boxes/1
{
"macaddress":"24-A4-3C-02-37-26"
}
PUT test/boxes/2
{
"macaddress":"24-A4-3C-02-37-54"
}
PUT test/boxes/3
{
"macaddress":"24-A4-3C-02-38-23"
}
PUT test/boxes/4
{
"macaddress":"34-A4-3C-02-38-23"
}
GET test/boxes/_search
{
"query": {
"multi_match": {
"query": "24-A4-3C-02",
"fields": ["macaddress.ngram",
"macaddress.sortable^5"]
}
}
}
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.047079325,
"hits": [
{
"_index": "test",
"_type": "boxes",
"_id": "1",
"_score": 0.047079325,
"_source": {
"macaddress": "24-A4-3C-02-37-26"
}
},
{
"_index": "test",
"_type": "boxes",
"_id": "2",
"_score": 0.047079325,
"_source": {
"macaddress": "24-A4-3C-02-37-54"
}
},
{
"_index": "test",
"_type": "boxes",
"_id": "3",
"_score": 0.047079325,
"_source": {
"macaddress": "24-A4-3C-02-38-23"
}
}
]
}
}
关于ruby-on-rails - Elasticsearch Ngram Analyzer搜索零件Mac地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29521371/
我有一个 Tizen Edje 文件,它定义了我的布局。其中一个部分是一张图像,其部分名称为“警告”。该项目在边缘文件中设置为可见,并且按预期显示。 我想使用 C 代码隐藏这部分: Evas_Obje
我正在开发一个 Eclipse RPC 项目。我需要保存和恢复所有 View 的所有内容。我没有在我的项目中使用 EMF,因此我无法使用所有 EMF API。 现在我可以使用的是IMemento。 I
我是一名优秀的程序员,十分优秀!