Elasticsearch非规范化数据查询

时间:2017-01-25 19:29:50

标签: javascript json elasticsearch firebase firebase-realtime-database

我还没有找到任何关于关系数据的弹性搜索的例子。

例如:

{
    part: {
        -KbH7E4YBTHvpRVo17P4: {
            description: "Macbook Pro Late 2016 3.3 GHZ"
            id_category: "-KbEGUZU9In8XcWOtNbu"
            id_subcategory: "-KbEGVWkmvycYEAiHAEj"
            manufacturer: "Apple"
        }
    },
    category: {
        -KbEGUZU9In8XcWOtNbu: {
            name: "Computer"
        }
    },
    subcategory: {
        -KbEGVWkmvycYEAiHAEj: {
            name: "Laptop"
        }
    }
}

如何创建一个查询,该查询采用搜索字符串并能够搜索零件,类别和子类别并返回找到的零件。因此,如果他们搜索" app"制造商会回应一下。如果他们输入" comp"该类别将命中,该部分将被退回。与子类别相同。

使用firebase数据库,他们强烈反对嵌套数据,所以我已经对所有内容进行了非规范化,但似乎弹性搜索网站上的每个示例都是嵌套数据。

我知道我可以将类别和子类别名称添加到其中,但如果它们发生变化,我必须跟上它们。

我在partItems中遇到了同样的问题,其中每个部分有多个partItems,并且这些问题链接到part和order,所以我需要将part和partItems分开。

这是映射:

// http://localhost:9200/firebase

{
  "firebase": {
    "aliases": {

    },
    "mappings": {
      "part": {
        "properties": {
          "description": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "id_category": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "id_subcategory": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "manufacturer": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "partitems": {
            "properties": {
              "-KbHaDD6aEwMYBW-Kj_Q": {
                "type": "boolean"
              },
              "-KbISzbdULqNRYflYrFt": {
                "type": "boolean"
              },
              "-KbJyfACXPL44FYQAwne": {
                "type": "boolean"
              },
              "-KbK5STKmY-3NEE-uher": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "partitem": {
        "properties": {
          "cost": {
            "type": "long"
          },
          "id_part": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "id_vendor": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "part_number": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "quantity": {
            "type": "long"
          }
        }
      },
      "subcategory": {
        "properties": {
          "-KbEGVWkmvycYEAiHAEj": {
            "properties": {
              "id_category": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "-KbEbSI2NohHad3dcvju": {
            "properties": {
              "id_category": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          }
        }
      },
      "category": {
        "properties": {
          "-KbEGUZU9In8XcWOtNbu": {
            "properties": {
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "subcategories": {
                "properties": {
                  "-KbEGVWkmvycYEAiHAEj": {
                    "type": "boolean"
                  },
                  "-KbEbSI2NohHad3dcvju": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1485328359842",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "xxx",
        "version": {
          "created": "5010299"
        },
        "provided_name": "firebase"
      }
    }
  }
}

0 个答案:

没有答案