2013-10-31 111 views
0

在我編制索引的每個文檔中,我都有一個名爲「永久鏈接」的字段,我想精確匹配。Elasticsearch中的字段完全匹配

一個例子文件:

{ 
    "entity_type": "company", 
    "entity_id": 1383221763, 
    "company_type": "developer", 
    "name": "Runewaker Entertainment", 
    "permalink": "runewaker-entertainment" 
} 

這些文件的映射:

{ 
    "properties": { 
     "entity_id": { 
      "type": "integer", 
      "include_in_all": false 
     }, 
     "name": { 
      "type": "string", 
      "include_in_all": true, 
     }, 
     "permalink": { 
      "type": "string", 
      "include_in_all": true, 
      "index": "not_analyzed" 
     }, 
     "company_type": { 
      "type": "string", 
      "include_in_all": false, 
      "index": "not_analyzed" 
     } 
    } 
} 

當我運行下面的查詢,然後我沒有得到任何點擊:

POST /companies/company/_search HTTP/1.1 
Host: localhost:8082 

{ 
    "query": { 
     "filtered": { 
      "query": { 
       "match_all": {} 
      }, 
      "filter": { 
       "term": { "permalink": "runewaker-entertainment" } 
      } 
     } 
    } 
} 

但我得到與此查詢匹配:

POST /companies/company/_search HTTP/1.1 
Host: localhost:8082 

{ 
    "query": { 
     "filtered": { 
      "query": { 
       "match_all": {} 
      }, 
      "filter": { 
       "term": { "permalink": "runewaker" } 
      } 
     } 
    } 
} 

它出現任何帶有連字符的固定鏈接導致查詢失敗,但我的印象是,如果屬性映射的索引設置爲not_analyzed,那麼ElasticSearch根本不會分析該字段。

正確的查詢應該是什麼?

謝謝


UPDATE:

在公司指數getMapping結果:你所描述的

{ 
    "companies" : { 
    "company" : { 
     "properties" : { 
     "company_type" : { 
      "type" : "string" 
     }, 
     "entity_id" : { 
      "type" : "long" 
     }, 
     "entity_type" : { 
      "type" : "string" 
     }, 
     "name" : { 
      "type" : "string" 
     }, 
     "node_id" : { 
      "type" : "long" 
     }, 
     "permalink" : { 
      "type" : "string" 
     } 
     } 
    } 
    } 
} 

回答

2

是正確的。

我測試過了,它按預期工作。所以你的索引可能有些問題。在設置映射之前,您是否可以爲文檔建立索引?
嘗試再次執行此操作 -
刪除您的索引或創建一個新索引。
用你的映射做一個putMapping。
索引文件。

搜索應該按預期工作。

+0

我試過我的配置在新的數據庫服務器上,它仍然不起作用 – alexbilbie

+0

可以附加getMapping的結果在您的索引? –

+0

我已經更新了原來的問題 – alexbilbie