无法在弹性搜索中搜索整数

时间:2017-07-11 10:30:06

标签: node.js elasticsearch integer elasticsearch.js elasticsearch-analyzers

我是弹性搜索的新手,我正在使用亚马逊的弹性搜索5.3。 这是我的json数据

[
    {
    "Sl. No.": 5,
    "Code No.": "0101.21.00",
    "Name of Commodity": "Live Horses"
  },
  {
    "Sl. No.": 6,
    "Code No.": "0101.29.00",
    "Name of Commodity": "some name"
  }
]

这是我在nodejs中设置数据加载的设置。

var client = new elasticsearch.Client({ 
  host: 'https://search-testdomain-mydomain.amazonaws.com',
  log: 'trace'
});

for (var i = 0; i < jsonfile.length; i++ ) {
  client.create({
    index: esindex, // name your index
    type: estype, // describe the data thats getting created
    id: i, // increment ID every iteration 
    body: jsonfile[i] 
  }, function(error, response) {
    if (error) {
      console.error(error);
      return;
    }
  });
}

和搜索代码是

client.search({
      index: esindex,
      type: estype,
      body: {
        query: {
          "multi_match" : {
            "query":      searchQuery,
            "fields":     [ "Sl. No.", "Name of Commodity", "Code No."],
            "operator":   "or" ,
             "analyzer":"standard"
              }
            }
        }
        }).then(function (resp) {
        console.log(resp);
});

当我搜索字符串时,它给出了正确的结果。 即

curl -XGET https://search-testdomain-mydomain.amazonaws.com/product/products/_search?pretty -d'
  {
    "query": {
      "multi_match": {
        "query": "Live Horses",
        "fields": [
          "Sl. No.",
          "Name of Commodity",
          "Code No."
        ],
        "operator": "or"
      }
    }
  }'

但是当我为整数做时,它没有给出结果

curl -XGET https://search-testdomain-mydomain.amazonaws.com/product/products/_search?pretty -d'
  {
    "query": {
      "multi_match": {
        "query": 1,
        "fields": [
          "Sl. No.",
          "Name of Commodity",
          "Code No."
        ],
        "operator": "or"
      }
    }
  }'

并且它可以正常卷曲调用,而无需指定任何字段

curl -XGET https://search-testdomain-mydomain.amazonaws.com/product/products/_search?pretty -d'
  {
    "query": {
      "query_string": {
        "query": 1
      }
    }
  }'

我读了许多帖子说我们需要添加分析器,即标准来处理整数..我尝试在创建时添加但是它抛出了错误。 我需要添加边缘NGram 分析器吗? 我没有得到如何处理这个如何在nodejs中添加分析器..请有人帮我解决这个问题?

1 个答案:

答案 0 :(得分:0)

如果要根据整数进行搜索,为什么不尝试使用过滤器选项

相关问题