具有相同类型的弹性搜索父级

时间:2015-07-30 03:33:46

标签: elasticsearch parent-child

很抱歉,如果这是重复的(我确实尝试过搜索),或者这是一个愚蠢的问题。发布问题的新手。

我正在尝试使用以下内容在ElasticSearch中进行父子关系和查询:

    #!/bin/bash

curl -XDELETE 'http://localhost:9200/test/'
echo

curl -XPUT 'http://localhost:9200/test/' -d '{
"settings" : {
        "index" : {
            "number_of_shards" : 1
        }
    }
}'
echo

curl -XPUT localhost:9200/test/_mapping/nelement -d '{
        "nelement" : {
            "_id" : { "path" : "nid", "store" : true, "index" : "not_analyzed"},
            "_parent" : { "type" : "nelement"},
            "properties" : {
                "name" : { "type" : "string",  "index" : "not_analyzed" },
                "nid": { "type" : "string", "copy_to" : "_id" }
            }
        }
}'
echo

#curl -s -XPOST localhost:9200/_bulk --data-binary @test_data.json
test_data.json is as follows:
{"index":{"_index":"test","_type":"element", "_parent":"abc"}
{"nid":"1a","name":"parent1"}
{"index":{"_index":"test","_type":"element", "_parent":"1a"}
{"nid":"2b","name":"child1"}
{"index":{"_index":"test","_type":"element", "_parent":"2b"}
{"nid":"2c","name":"child2"}


curl -XGET 'localhost:9200/test/nelement/_search?pretty=true' -d '{

 "query": {
    "has_child": {
      "child_type": "nelement", 
      "query": {
        "match": {
          "nid": "2c"
        }
      }
    }
  }

}'



echo
echo
curl -XGET 'localhost:9200/test/nelement/_search?pretty=true' -d '{

 "query": {
    "has_parent": {
      "type": "nelement", 
      "query": {
        "term": {
          "nid": "2b"
        }
      }
    }
  }

}'

出于某种原因,我的搜索查询没有结果。我已确认对象已编入索引....

1 个答案:

答案 0 :(得分:3)

因为您正在使用 自引用 在同一索引类型中设置父级和查询)来进行父/子查询。

目前Elasticsearch不支持它。

Explore parent/child self referential support