【问题标题】:couldn't search integers in elasticsearch无法在弹性搜索中搜索整数
【发布时间】:2017-12-15 08:45:11
【问题描述】:

我是 elasticsearch 新手,我正在使用亚马逊的 elasticsearch 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 调用,无需指定任何文件

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

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

【问题讨论】:

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


    【解决方案1】:

    如果你想根据整数搜索,为什么不尝试使用过滤选项

    【讨论】:

      猜你喜欢
      • 2016-02-27
      • 2022-08-12
      • 2014-03-02
      • 2018-10-26
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多