Elasticsearch。嵌套字段类型和原始字符串子字段

时间:2015-06-10 13:07:17

标签: elasticsearch

我有映射:


    {
       "properties":{
          /*some fields ommited*/,
          "properties":{
             "type":"nested",
             "properties":{
                "FieldA":{
                   "type":"string",
                   "fields":{
                      "raw":{
                         "index":"not_analyzed",
                         "type":"string"
                      }
                   }
                }
             }
          }
       }
    }

和一些文件:


    {
      /*some fields ommited*/,
       "properties":{
          "FieldA":"one"
       }
    }

    {
      /*some fields ommited*/,
       "properties":{
          "FieldA":"two"
       }
    }

等等。

我尝试进行查询:


    {
      "query": {
        "nested": {
          "query": {
            "term": {
              "FieldA.raw": "one"
            }
          },
          "path": "properties"
        }
      }
    }

没有找到结果。如果我尝试按字段使用相同的查询与其他类型(不是字符串,没有原始子字段),它的工作原理。我应该如何为该案件编写查询?谢谢!

P.S。 field" FieldA"子字段原始因为我需要对此字段进行分析而不是同时进行分析

1 个答案:

答案 0 :(得分:3)

您只需指定嵌套字段的完整路径:

{
   "query": {
      "nested": {
         "path": "properties",
         "query": {
            "term": {
               "properties.FieldA.raw": "one"
            }
         }
      }
   }
}

以下是我用来测试它的一些代码:

http://sense.qbox.io/gist/f2d9e5eae7496ca0fce8d2d23e17bf4d72d9300a