2017-10-26 5 views
0

에 백 슬래시 탈출 나는 시도했다 :어떻게 ElasticSerach 쿼리

"type": "doc\\\\doc1" 
"type": "\"doc\\\\doc1"\" 
"type": "\"doc\\doc1"\" 

그러나 쿼리는 결과를 반환하지 않는다.

나는 시도했다 :

GET /my_index/my_type/_search 
{ 
"query" : { 
    "query_string" : { 
    "query" : "doc\\doc1", 
    "analyzer": "keyword"  
    } 
} 
} 

그러나 동일한 출력입니다.

어떤 크게

감사를 감상 할 수 있도록 도와드립니다!

+0

https://stackoverflow.com/questions/45948547/trouble-escaping -elasticsearch-query/45951476 # 45951476 – Val

답변

0

필드 값에서 백 슬래시를 이스케이프 처리해야합니다.

그런 다음 용어 쿼리 키워드 분석으로 정확한 값을 검색 할 수 있습니다 또는 대신 분석 값과 일치하는 쿼리를 사용할 수 있습니다

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" 
      } 
     } 
     } 
    } 
} 
+0

감사합니다. 필드가 "field1": "doc \ doc1"이 아닌 "doc \\ doc1" –