我在ElasticSearch中有以下字段:
"type": "doc\doc1"我的目标是选择一个特殊的类型,我尝试过:
GET /my_index/my_type/_search
{
"query":{
"bool":{
"must":{
"term":{
"type": "doc\\doc1"
}
}
}
}
}但是它不起作用,我试过了:
"type": "doc\\\\doc1"
"type": "\"doc\\\\doc1"\"
"type": "\"doc\\doc1"\"但是查询不返回任何结果。
我尝试过:
GET /my_index/my_type/_search
{
"query" : {
"query_string" : {
"query" : "doc\\doc1",
"analyzer": "keyword"
}
}
} 但这是相同的输出。
任何帮助都将不胜感激
谢谢!
发布于 2017-10-26 17:51:58
您需要在字段值中转义反斜杠。
然后,您可以使用关键字分析器with term query搜索确切的值,或者您可以使用match query with analyzed:
PUT test
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"type1": {
"properties": {
"field1": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
PUT test/type1/1
{
"field1" : "doc\\doc1"
}
POST test/_search?pretty
{
"query": {
"bool": {
"must": {
"term": {
"field1.raw": "doc\\doc1"
}
}
}
}
}
POST test/_search?pretty
{
"query": {
"bool": {
"must": {
"match": {
"field1": "doc\\doc1"
}
}
}
}
}https://stackoverflow.com/questions/46950526
复制相似问题