2014-08-30 22 views
0

如果我運行下面有AND查詢返回什麼:彈性搜索和運營商不沃金

TF1:"rohan sharma" AND TF3:"gaurav" 

,但如果我用OR其返回結果:

TF1:"rohan sharma" OR TF3:"gaurav" 

兩個數據是可用的

這裏是映射:

{ 
    "TEST": { 
    "mappings": { 
     "indextestField1": { 
     "_ttl": { 
      "enabled": true 
     }, 
     "properties": { 
      "TF1": { 
      "type": "string" 
      }, 
      "TF2": { 
      "type": "string" 
      } 
     } 
     } 
    } 
    } 
} 

這裏是我的Java代碼

SearchResponse response = client.prepareSearch("TEST") 
     .setQuery(QueryBuilders.queryString("TF1:\"rohan sharma\" AND TF2:\"milind bagal\"")) 
     .execute() 
     .actionGet(); 
+0

不要更改爲「OR」運算符,請嘗試單獨運行每個子句,並確保您正在查找的文檔出現在兩者中。也就是說,嘗試使用TF1:\「rohan sharma \」「'和'」TF2:\「milind bagal \」「'作爲您的查詢字符串,確保您正在查找的文檔包含* both * 。 – femtoRgon 2014-08-30 19:32:25

回答

0

你的映射一定是錯誤的,你的分析添加到田間地頭TF1TF3

{ 
    "TEST": { 
    "mappings": { 
     "properties": { 
     "TF1": { 
      "type": "string", 
      "index": "not_analyzed" 
     }, 
     "TF2": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
    } 
} 

參考,

hack on elasticsearch (3 hrs)

Scripts example

0

關於您所提供的命令,雙引號的"rohan sharma",這意味着這兩個詞的位置必須位於訂購。

我猜你想找到的文件,這兩個詞"rohan sharma"不是彼此相鄰,這意味着這種情況失敗,並導致使用AND運算符不匹配。

所以,如果你不需要的位置條件,請不要使用雙引號,只是使用:

TF1:rohan AND TF1:sharma AND TF3:gaurav

這只是我的假設。要獲得更詳細的答案,您可能需要使用您提供的命令提供您想要查找的文檔。