elasticsearch elasticsearch |查询带有术语和术语不起作用的列表的文档,elasticsearch,elasticsearch" /> elasticsearch elasticsearch |查询带有术语和术语不起作用的列表的文档,elasticsearch,elasticsearch" />

elasticsearch elasticsearch |查询带有术语和术语不起作用的列表的文档

elasticsearch elasticsearch |查询带有术语和术语不起作用的列表的文档,elasticsearch,elasticsearch,我创建了一个文档,其中我存储了一个字段,如下所示。字段“community”存储为列表 { "_index": "test", "_type": "historic_participant1", "_id": "3", "_score": 1, "_source": { "community": [ "Cortez", "Retai

我创建了一个文档,其中我存储了一个字段,如下所示。字段“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"
      }
    }
  }
}

同样值得一提的是,该类型中的所有文档都存储了如上所述的社区值。非常感谢您的帮助。

默认情况下,您使用的是,它将您的输入小写

查询retail(小写)将产生预期结果:

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"
        }
      }
    ]
  }
}

您需要将您的请求小写,或者设置不同的分析器。

如果您对字段
社区
上的
全文
搜索没有问题,请告诉elasticsearch将
匹配短语
而不是
术语
查询

   "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": "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"
     }
    }
 }
参考


但令人惊讶的是,如果您只检查一个数组,就会出现这种情况。如果我使用一个简单的字符串类型,我必须提供确切的字符串,以便找到字段。例如:“term”:{“census_region”:{“value”:“West”},它给我搜索结果。但是如果我使用value:west。。它不。。如果你注意到。。在您提供的查询中,如果我使用“retail”作为all small进行查询,那么获取的结果是完美的,但它将retail显示为“retail”。有什么想法吗?我同意,这对初学者来说是相当混乱的。返回的结果与ES用于内部搜索的索引数据不同。返回的结果始终是原始的、未修改的文档。至于术语“West”,它可能太短,分析器无法解析,可能是一个停止词或类似的东西。