我创建了一个文档,其中我存储的字段如下。 Field" community"存储为列表。
{
"_index": "test",
"_type": "historic_participant1",
"_id": "3",
"_score": 1,
"_source": {
"community": [
"Cortez",
"Retail",
"NetAtmo"
],
"date": "2009-11-10T14:12:12",
"memberID": 3,
"validation": "valid",
"dal_is_installed": true,
"dal_is_flowing": true,
"is_flowing_dal_tablet": true,
"is_flowing_dal_computer": false,
"is_flowing_dal_smartphone": true,
"ss_is_installed": true,
"ss_is_flowing": true,
"ss_survey_responded_count": 5,
"dal_mobile_activity_count": 5,
"dal_tab_activity_count": 5,
"dal_computer_activity_count": 5,
"status": "verified"
}
以下是现场社区的映射:
"community": {
"type": "string"
},
现在,如果我使用以下任一术语或术语查询社区,我会在找到零文档时得到我的回复。有人可以帮忙。
{
"query": {
"term": {
"community": {
"value": "Retail"
}
}
}
}
另外,类型中的所有文档都存储了上述社区的价值。感谢帮助。
答案 0 :(得分:3)
默认情况下,您使用Standard Analyzer,这会降低您的输入。
查询零售(小写)将产生预期结果:
curl -XGET localhost:9200/twitter/tweet/_search -d '{
"query": {
"term": {
"community": {
"value": "retail"
}
}
}
}'
结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.15342641,
"hits": [
{
"_index": "twitter",
"_type": "tweet",
"_id": "1",
"_score": 0.15342641,
"_source": {
"community": [
"Cortez",
"Retail",
"NetAtmo"
],
"date": "2009-11-10T14:12:12",
"memberID": 3,
"validation": "valid",
"dal_is_installed": true,
"dal_is_flowing": true,
"is_flowing_dal_tablet": true,
"is_flowing_dal_computer": false,
"is_flowing_dal_smartphone": true,
"ss_is_installed": true,
"ss_is_flowing": true,
"ss_survey_responded_count": 5,
"dal_mobile_activity_count": 5,
"dal_tab_activity_count": 5,
"dal_computer_activity_count": 5,
"status": "verified"
}
}
]
}
}
您需要小写您的请求,或设置不同的分析器。
答案 1 :(得分:2)
如果您对full-text
字段community
进行搜索没问题,请将elasticsearch告诉match phrase
而不是term
查询,
"community": {
"type": "string"
},
和查询一样,
POST http://yourEsHost:9200/INDEX/TYPE/_search
{
"query": {
"match_phrase": {
"community": "Retail"
}
}
}
当你查询时,它也会给出结果,
POST http://yourEsHost:9200/INDEX/TYPE/_search
{
"query": {
"match_phrase": {
"community": "Cortez Retail"
}
}
}
或
POST http://yourEsHost:9200/INDEX/TYPE/_search
{
"query": {
"match_phrase": {
"community": "Cortez Retail NetAtmo"
}
}
}
<强>参考强>