作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用elasticsearch 6.8
并执行以下查询:
curl localhost:9200/twitter/_search?pretty=true -H 'Content-Type: application/json' -d '
{ "query": {"match_phrase": { "name": ".C" }}}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "twitter",
"_type" : "1",
"_id" : "2",
"_score" : 0.2876821,
"_source" : {
"name" : "my name C 100"
}
},
{
"_index" : "twitter",
"_type" : "1",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "my name .C 100"
}
}
]
}
}
.C
的文档被返回。我试图用
dot
逃脱
{"match_phrase": { "name": "\\.C" }}
,但是它不起作用。
name
的类型更改为
keyword
,因为我仍然需要标记器。
.
作为 protected 单词放在索引设置中,如下所示:
#curl localhost:9200/twitter/_settings?
{
"twitter" : {
"settings" : {
"index" : {
"number_of_shards" : "5",
"provided_name" : "twitter",
"creation_date" : "1579489541087",
"analysis" : {
"filter" : {
"word_delim_filter" : {
"type" : "word_delimiter",
"protected_words" : [
"."
]
}
},
"analyzer" : {
"content" : {
"type" : "custom",
"tokenizer" : "whitespace"
},
"custom_synonyms_delim" : {
"filter" : [
"word_delim_filter"
],
"tokenizer" : "whitespace"
}
}
},
"number_of_replicas" : "1",
"uuid" : "nYr7NPdVRCqIcTzzM_iBeQ",
"version" : {
"created" : "6080299"
}
}
}
}
}
dot
?
最佳答案
这是一个在您的方案中如何处理dot
的工作示例:
映射
PUT my_index
{
"settings": {
"analysis": {
"filter": {
"word_delim_filter": {
"type": "word_delimiter",
"type_table": [
". => ALPHANUM"
]
}
},
"analyzer": {
"content": {
"type": "custom",
"tokenizer": "whitespace"
},
"custom_synonyms_delim": {
"filter": [
"word_delim_filter"
],
"type": "custom",
"tokenizer": "keyword"
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "text",
"analyzer": "custom_synonyms_delim",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
POST my_index/_doc/1
{
"name" : "my name C 100"
}
POST my_index/_doc/2
{
"name" : "my name .C 100"
}
GET my_index/_search
{
"query": {
"match_phrase": {
"name": ".C"
}
}
}
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.6931472,
"_source" : {
"name" : "my name .C 100"
}
}
]
关于elasticsearch - 如何从 `match_phase`查询中转义特殊字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59816653/
我正在使用elasticsearch 6.8并执行以下查询: curl localhost:9200/twitter/_search?pretty=true -H 'Content-Type: app
我是一名优秀的程序员,十分优秀!