首页 > 解决方案 > 如何通过 id 选择商店库存中不存在的产品

问题描述

我有 2 个索引产品和 shop_inventory_6(商店明智的库存)产品映射

{
  "products_staging" : {
    "aliases" : { },
    "mappings" : {
      "product" : {
        "properties" : {
          "alternate_names" : {
            "type" : "text"
          },
          "brand" : {
            "properties" : {
              "id" : {
                "type" : "integer"
              },
              "image_url" : {
                "type" : "text",
                "index" : false
              },
              "name" : {
                "type" : "text",
                "analyzer" : "standard"
              }
            }
          },
          "brand_suggest" : {
            "type" : "completion",
            "analyzer" : "autocomplete",
            "search_analyzer" : "whitespace_analyzer",
            "preserve_separators" : true,
            "preserve_position_increments" : true,
            "max_input_length" : 50
          },
          "category" : {
            "properties" : {
              "id" : {
                "type" : "integer"
              },
              "image_url" : {
                "type" : "text",
                "index" : false
              },
              "name" : {
                "type" : "text",
                "analyzer" : "standard"
              }
            }
          },
          "id" : {
            "type" : "text"
          },
          "image_url" : {
            "type" : "text",
            "index" : false
          },
          "name" : {
            "type" : "text",
            "fields" : {
              "raw" : {
                "type" : "keyword"
              }
            },
            "analyzer" : "standard"
          },
          "name_suggest" : {
            "type" : "completion",
            "analyzer" : "autocomplete",
            "search_analyzer" : "whitespace_analyzer",
            "preserve_separators" : true,
            "preserve_position_increments" : true,
            "max_input_length" : 50
          },
          "product_alternate_name_suggest" : {
            "type" : "completion",
            "analyzer" : "autocomplete",
            "search_analyzer" : "whitespace_analyzer",
            "preserve_separators" : true,
            "preserve_position_increments" : true,
            "max_input_length" : 50
          },
          "product_sizes" : {
            "type" : "nested",
            "properties" : {
              "ean_code" : {
                "type" : "keyword"
              },
              "id" : {
                "type" : "integer"
              },
              "is_deleted" : {
                "type" : "boolean"
              },
              "price" : {
                "type" : "float"
              },
              "shop_category_type_ids" : {
                "type" : "text"
              },
              "uom" : {
                "type" : "keyword"
              },
              "weight" : {
                "type" : "float"
              }
            }
          },
          "sub_category" : {
            "properties" : {
              "alternate_names" : {
                "type" : "text"
              },
              "id" : {
                "type" : "integer"
              },
              "image_url" : {
                "type" : "text",
                "index" : false
              },
              "name" : {
                "type" : "text",
                "analyzer" : "standard"
              }
            }
          },
          "sub_category_alternate_suggest" : {
            "type" : "completion",
            "analyzer" : "autocomplete",
            "search_analyzer" : "whitespace_analyzer",
            "preserve_separators" : true,
            "preserve_position_increments" : true,
            "max_input_length" : 50
          },
          "sub_category_suggest" : {
            "type" : "completion",
            "analyzer" : "autocomplete",
            "search_analyzer" : "whitespace_analyzer",
            "preserve_separators" : true,
            "preserve_position_increments" : true,
            "max_input_length" : 50
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "number_of_shards" : "3",
        "provided_name" : "products_staging",
        "creation_date" : "1566968865962",
        "analysis" : {
          "filter" : {
            "autocomplete_filter" : {
              "type" : "edge_ngram",
              "min_gram" : "2",
              "max_gram" : "20"
            }
          },
          "analyzer" : {
            "autocomplete" : {
              "filter" : [
                "lowercase",
                "autocomplete_filter"
              ],
              "type" : "custom",
              "tokenizer" : "standard"
            },
            "whitespace_analyzer" : {
              "filter" : [
                "lowercase",
                "asciifolding"
              ],
              "type" : "custom",
              "tokenizer" : "whitespace"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "M5GE3TK9QOKVaBMcOkCJPQ",
        "version" : {
          "created" : "6000199"
        }
      }
    }
  }
}

shop_inventory 映射

{
  "staging_shop_inventory_17" : {
    "aliases" : { },
    "mappings" : {
      "shop_inventory" : {
        "properties" : {
          "brand" : {
            "properties" : {
              "created_at" : {
                "type" : "date"
              },
              "id" : {
                "type" : "integer"
              },
              "image" : {
                "type" : "text",
                "index" : false
              },
              "is_selected" : {
                "type" : "boolean"
              },
              "name" : {
                "type" : "text",
                "analyzer" : "standard"
              },
              "updated_at" : {
                "type" : "date"
              }
            }
          },
          "brand_suggest" : {
            "type" : "text",
            "analyzer" : "ngram_analyzer"
          },
          "category" : {
            "properties" : {
              "id" : {
                "type" : "integer"
              },
              "image" : {
                "type" : "text",
                "index" : false
              },
              "name" : {
                "type" : "text",
                "analyzer" : "standard"
              }
            }
          },
          "deleted_at" : {
            "type" : "date"
          },
          "id" : {
            "type" : "integer"
          },
          "image" : {
            "type" : "text",
            "index" : false
          },
          "is_deleted" : {
            "type" : "boolean"
          },
          "name" : {
            "type" : "text",
            "fields" : {
              "raw" : {
                "type" : "keyword"
              }
            },
            "analyzer" : "gramAnalyzer",
            "search_analyzer" : "whitespace_analyzer"
          },
          "name_suggest" : {
            "type" : "text",
            "analyzer" : "ngram_analyzer"
          },
          "product_deleted" : {
            "type" : "keyword"
          },
          "product_id" : {
            "type" : "integer"
          },
          "product_sizes" : {
            "type" : "nested",
            "properties" : {
              "deleted_at" : {
                "type" : "date"
              },
              "ean_code" : {
                "type" : "keyword"
              },
              "id" : {
                "type" : "integer"
              },
              "in_stock" : {
                "type" : "boolean"
              },
              "is_deleted" : {
                "type" : "boolean"
              },
              "price" : {
                "type" : "float"
              },
              "product_update_on" : {
                "type" : "date"
              },
              "product_update_status" : {
                "type" : "integer"
              },
              "uom" : {
                "type" : "keyword"
              },
              "weight" : {
                "type" : "float"
              }
            }
          },
          "sub_category" : {
            "properties" : {
              "created_at" : {
                "type" : "date"
              },
              "id" : {
                "type" : "integer"
              },
              "image" : {
                "type" : "text",
                "index" : false
              },
              "is_selected" : {
                "type" : "boolean"
              },
              "name" : {
                "type" : "text",
                "analyzer" : "standard"
              },
              "updated_at" : {
                "type" : "date"
              }
            }
          },
          "sub_category_suggest" : {
            "type" : "text",
            "analyzer" : "gramAnalyzer",
            "search_analyzer" : "whitespace_analyzer"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "number_of_shards" : "3",
        "provided_name" : "staging_shop_inventory_17",
        "creation_date" : "1569230448054",
        "analysis" : {
          "filter" : {
            "gramFilter" : {
              "token_chars" : [
                "letter",
                "digit"
              ],
              "min_gram" : "1",
              "type" : "edge_ngram",
              "max_gram" : "20"
            }
          },
          "analyzer" : {
            "whitespace_analyzer" : {
              "filter" : [
                "lowercase",
                "asciifolding"
              ],
              "type" : "custom",
              "tokenizer" : "whitespace"
            },
            "ngram_analyzer" : {
              "token_chars" : [
                "letter",
                "digit"
              ],
              "min_gram" : "4",
              "type" : "custom",
              "max_gram" : "20",
              "tokenizer" : "ngram"
            },
            "gramAnalyzer" : {
              "filter" : [
                "lowercase",
                "asciifolding",
                "gramFilter"
              ],
              "type" : "custom",
              "tokenizer" : "whitespace"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "q9BkwXMVQnGoga8tznNFgg",
        "version" : {
          "created" : "6000199"
        }
      }
    }
  }
}

我想从产品索引中选择不在 shop_inventory 索引中的产品。没有两个查询

我还想通过 sub_category_id 和 brand_ids 选择产品,其中我有多个 sub_category_id 和品牌 ID(因为我的品牌属于多个类别)而不使用 OR 条件

标签: ruby-on-railselasticsearch

解决方案


推荐阅读