简体   繁体   English

并非所有术语都可在ElasticSearch查询中使用

[英]Not all terms work in ElasticSearch Query

I'm not seeing the results I expected when using term searching as described by https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html所述,在使用术语搜索时,我没有看到预期的结果

The ElasticSearch version is 2.3.2: Using this to create the data: ElasticSearch版本为2.3.2:使用它来创建数据:

curl -XPUT http://myelastic:9201/myindex/mytype/90273504?pretty=true -d '{ "CLIENT_ID" : "000000001", "USER_TYPE" : "ABC"}'
curl -XPUT http://myelastic:9201/myindex/mytype/90273505?pretty=true -d '{ "CLIENT_ID" : "000000002", "USER_TYPE" : "ABC"}'

This query shows both records: 此查询显示两条记录:

curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" -d '{ "query" : { "match_all" : { } } }'

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "myindex",
      "_type" : "mytype",
      "_id" : "90273505",
      "_score" : 1.0,
      "_source" : {
        "CLIENT_ID" : "000000002",
        "USER_TYPE" : "ABC"
      }
    }, {
      "_index" : "myindex",
      "_type" : "mytype",
      "_id" : "90273504",
      "_score" : 1.0,
      "_source" : {
        "CLIENT_ID" : "000000001",
        "USER_TYPE" : "ABC"
      }
    } ]
  }
}

This query shows one record, as expected: 此查询显示一条记录,如预期的那样:

curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
    -d '{ "query" : { "bool" : { "should" : [ { "term" : { "CLIENT_ID" : "000000001" } } ] } } }'

But using a different term results in no records: 但是,使用其他术语将不会产生任何记录:

curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
    -d '{ "query" : { "bool" : { "should" : [ { "term" : { "USER_TYPE" : "ABC" } } ] } } }'

Ultimately I want to score records based on matches on multiple terms, starting with a selection on multiple terms like this: 最终,我想根据多个术语的匹配来对记录进行评分,首先是对多个术语进行如下选择:

curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
    -d '{ "query" : { "bool" : { "should" : [ { "term" : { "CLIENT_ID" : "000000001" } }, { "term" : { "USER_TYPE" : "ABC" } } ] } } }'

But right now I'm trying to understand why 但是现在我想了解为什么

curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
    -d '{ "query" : { "bool" : { "should" : [ { "term" : { "USER_TYPE" : "ABC" } } ] } } }'

returns no records. 不返回任何记录。

Standard analyzer 标准分析仪

The standard analyzer is the default analyzer that Elasticsearch uses. 标准分析器是Elasticsearch使用的默认分析器。 It is the best general choice for analyzing text that may be in any language. 这是分析可能使用任何语言的文本的最佳常规选择。 It splits the text on word boundaries, as defined by the Unicode Consortium, and removes most punctuation. 它按照Unicode联合会的定义在单词边界上分割文本,并删除大多数标点符号。 Finally, it lowercases all terms. 最后,它会全部小写。

https://www.elastic.co/guide/en/elasticsearch/guide/current/analysis-intro.html#_built_in_analyzers https://www.elastic.co/guide/en/elasticsearch/guide/current/analysis-intro.html#_built_in_analyzers

Try to search lower case text. 尝试搜索小写文本。 I think it works with numbers because they have no case. 我认为它适用于数字,因为它们没有大小写。

curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
    -d '{ "query" : { "bool" : { "should" : [ { "term" : { "USER_TYPE" : "abc" } } ] } } }'

This thread could help 这个线程可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM