【问题标题】:Elastic Search: Find All Records By Single Phrase弹性搜索:按单个短语查找所有记录
【发布时间】:2015-03-05 13:55:10
【问题描述】:

我正在使用 elastic-search-1.4.4。这是我的查询:

   { 
    "query": { 
          "filtered": { 
             "filter": { "term": { "Name": "n" } } 
        } 
     } 
   }

这是我的索引文件:

   {
     "took" : 2,
     "timed_out" : false,
     "_shards" : {
      "total" : 5,
      "successful" : 5,
     "failed" : 0
    },
     "hits" : {
       "total" : 12,
       "max_score" : 1.0,
       "hits" : [ {
       "_index" : "mytry",
       "_type" : "users",
       "_id" : "23",
       "_score" : 1.0,
         "_source":{"ID":23,"Name":"Abudul Rafay","Email":"a","Password":"afasd"}
}, {
       "_index" : "mytry",
       "_type" : "users",
       "_id" : "28",
       "_score" : 1.0,
       "_source":{"ID":28,"Name":"helo","Email":"helo","Password":"heko"}
}, {
       "_index" : "mytry",
      "_type" : "users",
      "_id" : "30",
     "_score" : 1.0,
     "_source":{"ID":30,"Name":"nup","Email":"nup","Password":"nup"}
}, {
     "_index" : "mytry",
     "_type" : "users",
     "_id" : "31",
     "_score" : 1.0,
     "_source":{"ID":31,"Name":"apex","Email":"apex","Password":"apex"}
}, {
     "_index" : "mytry",
     "_type" : "users",
     "_id" : "29",
     "_score" : 1.0,
     "_source":{"ID":29,"Name":"change","Email":"change","Password":"change"}
},   {
       "_index" : "mytry",
    "_type" : "users",
      "_id" : "24",
    "_score" : 1.0,
    "_source":{"ID":24,"Name":"rafay","Email":"hello","Password":"fasfas"}
}, {
     "_index" : "mytry",
     "_type" : "users",
     "_id" : "32",
     "_score" : 1.0,
      "_source":{"ID":32,"Name":"newtry","Email":"newtry","Password":"newtry"}
}, {
      "index" : "mytry",
     "_type" : "users",
     "_id" : "25",
     "_score" : 1.0,
     "_source":{"ID":25,"Name":"r rafay ","Email":"r rafay","Password":"r rafay"}
}, {
     "_index" : "mytry",
     "_type" : "users",
     "_id" : "19",
     "_score" : 1.0,
     "_source":{"ID":19,"Name":"n","Email":"a","Password":"a"}
}, {
     "_index" : "mytry",
     "_type" : "users",
     "_id" : "26",
     "_score" : 1.0,
    "_source":{"ID":26,"Name":"New User","Email":"New","Password":"new"}
      } ]
      }
   }

这是我运行上述查询后的结果:

     {
      "took" : 2,
      "timed_out" : false,
      "_shards" : {
      "total" : 5,
      "successful" : 5,
      "failed" : 0
     },
     "hits" : {
        "total" : 1,
        "max_score" : 1.0,
        "hits" : [ {
            "_index" : "mytry",
            "_type" : "users",
             "_id" : "19",
            "_score" : 1.0,
          "_source":{"ID":19,"Name":"n","Email":"a","Password":"a"}
          } ]
        }
       }

所以,我想获取所有在名称字段中开始或包含单词“n”的记录。我尝试过聚合,但它不起作用。

【问题讨论】:

  • 为此,您需要使用 Ngram Token 过滤器。

标签: mysql elasticsearch


【解决方案1】:

您可以为此使用通配符查询。术语查询将检查完全匹配。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html

【讨论】:

    猜你喜欢
    • 2021-08-06
    • 2014-10-18
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多