【发布时间】:2016-08-02 18:42:46
【问题描述】:
使用https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html 所述的术语搜索时,我没有看到预期的结果
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"}'
此查询显示两条记录:
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"
}
} ]
}
}
此查询按预期显示一条记录:
curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
-d '{ "query" : { "bool" : { "should" : [ { "term" : { "CLIENT_ID" : "000000001" } } ] } } }'
但是使用不同的术语会导致没有记录:
curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
-d '{ "query" : { "bool" : { "should" : [ { "term" : { "USER_TYPE" : "ABC" } } ] } } }'
最终,我想根据多个术语的匹配对记录进行评分,从多个术语的选择开始,如下所示:
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" } } ] } } }'
但现在我正试图理解为什么
curl -D - -o - http://myelastic:9201/myindex/mytype/_search?pretty=true -H"Accept: application/json" \
-d '{ "query" : { "bool" : { "should" : [ { "term" : { "USER_TYPE" : "ABC" } } ] } } }'
不返回任何记录。
【问题讨论】:
标签: elasticsearch