【问题标题】:Why do I get 0 results为什么我得到 0 个结果
【发布时间】:2016-05-25 04:23:47
【问题描述】:

我使用 elasticsearch shingles 为小型搜索应用程序构建了一个自动完成功能。当我测试分析器和令牌时,一切似乎都设置正确。

    PUT /autocomplete
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    },
    "analysis": {
      "filter": {
        "autocomplete_shingles_filter": {
          "type": "shingle",
          "min_shingle_size": 2,
          "max_shingle_size": 5,
          "output_unigrams": false
        }
      },
      "analyzer": {
        "autocomplete_shingles_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
          "lowercase",
          "autocomplete_shingles_filter"
          ]
        }
      }
    }
  }
}

GET /autocomplete/_analyze?analyzer=autocomplete_shingles_analyzer&text=2010 toyota camry

但是当我去实际创建索引和映射并使用带有 _all 字段的匹配查询时,我得到 0 个结果

"mappings": {
"suggestions": {
  "_all": {
    "enabled": true,
    "index_analyzer": "autocomplete_analyzer",
    "search_analyzer": "autocomplete_analyzer"
  },
  "properties": {
    "makes": {
      "type": "string",
      "include_in_all": true
      },
      "models": {
        "type": "string",
        "include_in_all": true
      },
      "years": {
        "type": "string",
        "include_in_all": true
        }
      }
    }
  }
}

这是数据样本

    PUT /autocomplete/suggestions/_bulk
{"index": {"_id":"1"}}
{"years": ["2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017"]}
{"index": {"_id":"2"}}
{"makes": "Acura", "models": ["Legend Integra NSX Vigor TL RL SLX CL MDX RSX TSX RDX ZDX"]}
{"index": {"_id":"3"}}
{"makes": "Alfa Romeo", "models": ["164 Spider"]}
{"index": {"_id":"4"}}
{"makes": "Aston Martin", "models": ["DB9 Vanquish S DB9 Volante V8 Vantage Vantage DBS Rapide V8 Vantage S V12 Vantage Virage"]}
{"index": {"_id":"5"}}
{"makes": "Alfa Romeo", "models": ["164 Spider"]}

为什么当我使用验证分析器 API 时这会起作用,但是当我实际创建索引、映射和查询时……我得到 0 个结果?我做错了什么?

更新

   {
  "query": {
    "match": {
      "_all": {
        "query": "2010 acura integra",
        "operator": "and"
      }
    }
  }
}

更新 2 我相信我已经弄清楚了,我使用的是 operator: 和 - 这意味着所有术语都必须在所有字段中,这是行不通的。删除运算符,我得到结果。但是,在我的测试中,多匹配查询似乎更适合这个,因为 1)我可以提升字段 2)我不需要使用 _all 字段 3)似乎它有更好的选项来调整查询以随着时间的推移对其进行微调,我在正确的轨道上吗?

【问题讨论】:

  • 您使用的查询是什么?
  • @AndreiStefan,请查看 _all 字段上的更新、匹配查询 - 有没有更好的查询可供使用?

标签: elasticsearch


【解决方案1】:

您不应该在_all 字段中使用autocomplete_shingles_analyzer 而不是autocomplete_analyzer 吗?

【讨论】:

  • Zatarain,感谢您的提醒,已修复,但仍然没有结果
猜你喜欢
  • 2013-01-25
  • 2020-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多