2017-10-26 27 views
0

にバックスラッシュをエスケープする私はElasticSearchで、次のフィールドがあります。どのようElasticSerachクエリ

GET /my_index/my_type/_search 
{ 
"query":{ 
    "bool":{ 
    "must":{ 
     "term":{ 
      "type": "doc\\doc1" 
     } 
    } 
    } 
} 
} 

をそれがない作品を行い、:私の目標は、特殊なタイプを選択することです

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

しかし、それは同じ出力です。

どれが大幅

感謝をいただければ幸いに役立ちます!

+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"ではなく "field1": "doc \ doc1" –