[英]Elasticsearch: getting documents with exactly a certain value in a field
我有一個包含一些重復文本內容的文檔的索引,我需要檢索具有完全相同值而不是相似值的文檔。 因此,例如,將以下每一行視為不同文檔的“文本”屬性的值:
所以我需要的是只檢索標有(*)的兩個文檔。 我試過:
GET news/_search
{
"_source": ["text"],
"min_score": 1,
"query": {
"simple_query_string" : {
"query": "The car",
"fields": ["text"],
"flags": "NONE",
"minimum_should_match": "100%"
}
}
}
但它總是檢索所有 4 個文檔。 我也嘗試過使用 match_phrase 並且得到了相同的結果。
PS:我需要能夠運行兩個查詢:一個檢索 4 個文檔,另一個檢索僅 2 個。
這是映射:
{
"news" : {
"aliases" : { },
"mappings" : {
"tweet" : {
"properties" : {
"text" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
...
}
}
}
}
}
任何的想法?
謝謝
對於完全匹配,您應該在字段的關鍵字類型上使用 elasticsearch 的Term Query
。 用這個作為例子。
{
"query": {
"term": {
"text.keyword": {
"value": "The car"
}
}
}
}
上面的查詢將只返回 2 個結果。 但是如果你想獲取所有的結果去Match
查詢
{
"query": {
"match": {
"text": "The car"
}
}
}
這將返回所有四個結果。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.