【问题标题】:Elastic Search parent with same type具有相同类型的 Elastic Search 父级
【发布时间】:2015-07-30 13:51:37
【问题描述】:

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

我正在尝试使用以下方法在 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"
        }
      }
    }
  }

}'

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

【问题讨论】:

    标签: elasticsearch parent-child


    【解决方案1】:

    因为您使用自引用将父级和查询设置为相同的索引类型)来进行父/子查询。

    目前 Elasticsearch 不支持它。

    Explore parent/child self referential support

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 2014-01-10
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      相关资源
      最近更新 更多