2015-12-08 87 views
0

我正在嘗試查找包含字符串數組中特定術語的文檔。在數組中查找包含特定術語的文檔

我有這樣一個模式:

{ 
    "pages": { 
    "mappings":{ 
     "site":{ 
     "properties":{ 
      "urls":{"type":"string"} 
     } 
     } 
    } 
    } 
} 

和索引就可以了以下數據:

% curl -XPOST 'http://local.dev:9200/pages/site/_search?pretty 
{ 
    ... 
    "hits" : { 
    "total" : 1, 
    "max_score" : 1.0, 
    "hits" : [ { 
     "_index" : "pages", 
     "_type" : "site", 
     "_id" : "ae634fea-878f-42ca-8239-c67cca007a38", 
     "_score" : 1.0, 
     "_source":{ "urls":["https://github.com/fulano","http://fulano.com"] } 
    } 
    } 

我試圖尋找其URL數組包含特定的URL地點,但我無法讓它工作。我試着用terms - 精確描述here,但我從來沒有得到任何結果:

% curl -XPOST 'http://local.dev:9200/pages/site/_search?pretty' -d ' 
{ 
    "query": { 
    "filtered": { 
     "filter": { 
      "term": { "urls": "https://github.com/fulano" } 
     } 
    } 
    } 
}' 
{ 
    "hits" : { 
    "total" : 0, 
    "max_score" : null, 
    "hits" : [ ] 
    } 
} 

使用條款(即被擴大成由彈性一系列布爾操作):

% curl -XPOST 'http://local.dev:9200/pages/site/_search?pretty' -d ' 
{ 
    "query": { 
    "terms" : { 
     "urls" : ["https://github.com/fulano"] 
    } 
    } 
}' 
{ 
    "hits" : { 
    "total" : 0, 
    "max_score" : null, 
    "hits" : [ ] 
    } 
} 

我猜這真的很愚蠢,但我無法發現問題。 :(

+1

這【答案】(http://stackoverflow.com/questions/34133218/how -to-escape-a-url-for-elasticsearch/34135587#34135587)完全顯示你需要什麼。 – Val

回答

2

這是您所使用的分析儀的問題。你需要使用not_analyzed或關鍵字標記生成器所概述here

相關問題