Elasticsearch:如何查询长字段以进行完全匹配

时间:2015-01-05 06:46:45

标签: elasticsearch

我的文档具有以下映射属性:

"sid" : {"type" : "long", "store": "yes", "index": "no"},

此属性对每条记录只有一个值。我想查询这个属性。我尝试了以下查询:

{
    "query" : {
        "term" : {
             "sid" : 10
        }
    }
}

{
    "query" : {
        "match" : {
             "sid" : 10
        }
    }
}

然而,我没有结果。我有一个文件,sid是euqal到10.我做的任何事都错了?我想查询此属性以获得完全匹配。

谢谢和问候。

1 个答案:

答案 0 :(得分:2)

引自the documentation

  

index:设置为analyzed以便将字段编入索引并在搜索后进行搜索   使用分析器分解成令牌。 not_analyzed意味着它   仍然可以搜索,但不会通过任何分析过程或   分解成代币。 no意味着它根本无法搜索   (作为单个字段;它可能仍包含在_all中)。设置为   no停用include_in_all。默认为analyzed

因此,通过将index设置为no,您无法单独搜索该字段。因此,您需要从no中移除index并选择其他内容,或者您​​可以使用"include_in_all":"yes"并使用其他类型的查询:

  "query": {
    "match": {
      "_all": 10
    }
  }