Elasticsearch中带有连字符的索引字段

Mar*_*ope 6 elasticsearch

我正在尝试设计如何配置elasticsearch,以便我可以在包含连字符的字段上使用通配符进行查询字符串搜索.

我的文档看起来像这样:

{
   "tags":[
      "deck-clothing-blue",
      "crew-clothing",
      "medium"
   ],
   "name":"Crew t-shirt navy large",
   "description":"This is a t-shirt",
   "images":[
      {
         "id":"ba4a024c96aa6846f289486dfd0223b1",
         "type":"Image"
      },
      {
         "id":"ba4a024c96aa6846f289486dfd022503",
         "type":"Image"
      }
   ],
   "type":"InventoryType",
   "header":{
   }
}
Run Code Online (Sandbox Code Playgroud)

我试过使用word_delimiter过滤器和空格标记器:

{
"settings" : {
    "index" : {
        "number_of_shards" : 1,
        "number_of_replicas" : 1
    },  
    "analysis" : {
        "filter" : {
            "tags_filter" : {
                "type" : "word_delimiter",
                "type_table": ["- => ALPHA"]
            }   
        },
        "analyzer" : {
            "tags_analyzer" : {
                "type" : "custom",
                "tokenizer" : "whitespace",
                "filter" : ["tags_filter"]
            }
        }
    }
},
"mappings" : {
    "yacht1" : {
        "properties" : {
            "tags" : {
                "type" : "string",
                "analyzer" : "tags_analyzer"
            }
        }
    }
}
}
Run Code Online (Sandbox Code Playgroud)

但这些是搜索(标签)及其结果:

deck*     -> match
deck-*    -> no match
deck-clo* -> no match
Run Code Online (Sandbox Code Playgroud)

谁能看到我哪里出错了?

谢谢 :)

con*_*t47 9

分析仪很好(虽然我丢失了过滤器),但你的搜索分析器没有指定,所以它使用标准分析器搜索标签字段,它删除连字符然后尝试查询它(运行curl "localhost:9200/_analyze?analyzer=standard" -d "deck-*"看看是什么我的意思是)

基本上,"deck-*"被搜索为"deck*",没有任何单词只有"deck",所以它失败了.

正在搜索"deck-clo*"作为"deck clo*",同样没有单词只是"deck"或以"clo"开头,因此查询失败.

我做了以下修改

"analysis" : {
    "analyzer" : {
        "default" : {
            "tokenizer" : "whitespace",
            "filter" : ["lowercase"] <--- you don't need this, just thought it was a nice touch
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后摆脱标签上的特殊分析器

"mappings" : {
    "yacht1" : {
        "properties" : {
            "tags" : {
                "type" : "string"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

让我知道事情的后续.