0

我是弹性搜索的新手,我正在使用亚马逊的弹性搜索 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);
});

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

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 调用,无需指定任何文件

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

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

4

1 回答 1

0

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

于 2017-07-11T17:33:54.040 回答