单词的Elasticsearch术语查询包含另一个单词

时间:2016-08-06 07:00:42

标签: elasticsearch full-text-search nosql

我的映射是:

  "alarmName" : {
    "type" : "string",
    "norms" : {
      "enabled" : false
    },
    "analyzer" : "lowercase_analyzer"
  }

并设置为:

    "analysis" : {
      "analyzer" : {
        "lowercase_analyzer" : {
          "filter" : [ "lowercase" ],
          "tokenizer" : "keyword"
        }
      }
    }

我用alarmName =“pro profile”索引一些事件。

但当我查询时:

{
  "query" : {
    "term" : {
      "alarmName" : "pro profile"
    }
  }
}

我一无所获 但是有了这个问题:

{ 
  "size" : 0, 
  "aggs" : { 
    "alarms" : { 
      "terms" : { 
        "field" : "alarmName", 
        "size" : 100 
      }
    }
  }
}

我得到了这个结果:

{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 175023,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "alarms": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "multi app profile",
          "doc_count": 166733
        },
        {
          "key": "not mac profile",
          "doc_count": 3755
        },
        {
          "key": "port profile",
          "doc_count": 1579
        },
        {
          "key": "not ip profile",
          "doc_count": 932
        },
        {
          "key": "not pro  profile",
          "doc_count": 543
        },
        {
          "key": "not app profile",
          "doc_count": 507
        },
        {
          "key": "app profile",
          "doc_count": 370
        },
        {
          "key": "mac profile",
          "doc_count": 365
        },
        {
          "key": "ip profile",
          "doc_count": 114
        },
        {
          "key": "pro  profile",
          "doc_count": 94
        },
        {
          "key": "not port profile",
          "doc_count": 31
        }
      ]
    }
  }
}

对于所有其他带空格的单词,每件事情都可以,但对于这些单词(pro profile)我有这个问题。
这是一个错误?
这是为该配置文件包含pro?

1 个答案:

答案 0 :(得分:0)

因为我应该搜索专业资料(有2个空格)而不是专业资料(1个空格)

这是我的错误