Query on nested object does not return any hits

Hi,

I use elasticsearch for my webshop and indexed my products. But now i try
to perfom a query on a nested object but it's not working. Here is my
mapping:

http://localhost:9200/defaultindex/Product/_mapping?pretty=true

{
"Product" : {
"properties" : {
"additionalShippingCharge" : {
"type" : "double"
},
"adminComment" : {
"type" : "string"
},
"allowBackInStockSubscriptions" : {
"type" : "boolean"
},
"allowCustomerReviews" : {
"type" : "boolean"
},
"allowedQuantities" : {
"type" : "string"
},
"approvedRatingSum" : {
"type" : "integer"
},
"approvedTotalReviews" : {
"type" : "integer"
},
"automaticallyAddRequiredProducts" : {
"type" : "boolean"
},
"availableEndDateTimeUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"availableForPreOrder" : {
"type" : "boolean"
},
"availableStartDateTimeUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"backorderMode" : {
"type" : "long"
},
"backorderModeId" : {
"type" : "integer"
},
"callForPrice" : {
"type" : "boolean"
},
"categories" : {
"type" : "nested",
"properties" : {
"allowCustomersToSelectPageSize" : {
"type" : "boolean"
},
"categoryTemplateId" : {
"type" : "integer"
},
"createdOnUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"deleted" : {
"type" : "boolean"
},
"description" : {
"type" : "string"
},
"displayOrder" : {
"type" : "integer"
},
"hasDiscountsApplied" : {
"type" : "boolean"
},
"id" : {
"type" : "integer"
},
"includeInTopMenu" : {
"type" : "boolean"
},
"limitedToStores" : {
"type" : "boolean"
},
"metaDescription" : {
"type" : "string"
},
"metaKeywords" : {
"type" : "string"
},
"metaTitle" : {
"type" : "string"
},
"name" : {
"type" : "string"
},
"pageSize" : {
"type" : "integer"
},
"pageSizeOptions" : {
"type" : "string"
},
"parentCategoryId" : {
"type" : "integer"
},
"pictureId" : {
"type" : "integer"
},
"priceRanges" : {
"type" : "string"
},
"published" : {
"type" : "boolean"
},
"showOnHomePage" : {
"type" : "boolean"
},
"subjectToAcl" : {
"type" : "boolean"
},
"updatedOnUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
}
}
},
"createdOnUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"customerEntersPrice" : {
"type" : "boolean"
},
"deleted" : {
"type" : "boolean"
},
"deliveryDateId" : {
"type" : "integer"
},
"disableBuyButton" : {
"type" : "boolean"
},
"disableWishlistButton" : {
"type" : "boolean"
},
"displayOrder" : {
"type" : "integer"
},
"displayStockAvailability" : {
"type" : "boolean"
},
"displayStockQuantity" : {
"type" : "boolean"
},
"downloadActivationType" : {
"type" : "long"
},
"downloadActivationTypeId" : {
"type" : "integer"
},
"downloadExpirationDays" : {
"type" : "integer"
},
"downloadId" : {
"type" : "integer"
},
"fullDescription" : {
"type" : "string"
},
"giftCardType" : {
"type" : "long"
},
"giftCardTypeId" : {
"type" : "integer"
},
"gtin" : {
"type" : "string"
},
"hasDiscountsApplied" : {
"type" : "boolean"
},
"hasSampleDownload" : {
"type" : "boolean"
},
"hasTierPrices" : {
"type" : "boolean"
},
"hasUserAgreement" : {
"type" : "boolean"
},
"height" : {
"type" : "double"
},
"id" : {
"type" : "integer"
},
"imageUrl" : {
"type" : "string"
},
"isDownload" : {
"type" : "boolean"
},
"isFreeShipping" : {
"type" : "boolean"
},
"isGiftCard" : {
"type" : "boolean"
},
"isRecurring" : {
"type" : "boolean"
},
"isShipEnabled" : {
"type" : "boolean"
},
"isTaxExempt" : {
"type" : "boolean"
},
"length" : {
"type" : "double"
},
"limitedToStores" : {
"type" : "boolean"
},
"lowStockActivity" : {
"type" : "long"
},
"lowStockActivityId" : {
"type" : "integer"
},
"manageInventoryMethod" : {
"type" : "long"
},
"manageInventoryMethodId" : {
"type" : "integer"
},
"manufacturerPartNumber" : {
"type" : "string"
},
"manufacturers" : {
"type" : "nested",
"properties" : {
"allowCustomersToSelectPageSize" : {
"type" : "boolean"
},
"createdOnUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"deleted" : {
"type" : "boolean"
},
"description" : {
"type" : "string"
},
"displayOrder" : {
"type" : "integer"
},
"id" : {
"type" : "integer"
},
"limitedToStores" : {
"type" : "boolean"
},
"manufacturerTemplateId" : {
"type" : "integer"
},
"metaDescription" : {
"type" : "string"
},
"metaKeywords" : {
"type" : "string"
},
"metaTitle" : {
"type" : "string"
},
"name" : {
"type" : "string"
},
"pageSize" : {
"type" : "integer"
},
"pageSizeOptions" : {
"type" : "string"
},
"pictureId" : {
"type" : "integer"
},
"priceRanges" : {
"type" : "string"
},
"published" : {
"type" : "boolean"
},
"subjectToAcl" : {
"type" : "boolean"
},
"updatedOnUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
}
}
},
"maxNumberOfDownloads" : {
"type" : "integer"
},
"maximumCustomerEnteredPrice" : {
"type" : "double"
},
"metaDescription" : {
"type" : "string"
},
"metaKeywords" : {
"type" : "string"
},
"metaTitle" : {
"type" : "string"
},
"minStockQuantity" : {
"type" : "integer"
},
"minimumCustomerEnteredPrice" : {
"type" : "double"
},
"name" : {
"type" : "string"
},
"notApprovedRatingSum" : {
"type" : "integer"
},
"notApprovedTotalReviews" : {
"type" : "integer"
},
"notifyAdminForQuantityBelow" : {
"type" : "integer"
},
"oldPrice" : {
"type" : "double"
},
"orderMaximumQuantity" : {
"type" : "integer"
},
"orderMinimumQuantity" : {
"type" : "integer"
},
"parentGroupedProductId" : {
"type" : "integer"
},
"preOrderAvailabilityStartDateTimeUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"price" : {
"type" : "double"
},
"productAttributeFilterItems" : {
"type" : "nested",
"properties" : {
"filterAttributeOptions" : {
"properties" : {
"filterId" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
},
"filterId" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
},
"productCost" : {
"type" : "double"
},
"productTemplateId" : {
"type" : "integer"
},
"productType" : {
"type" : "long"
},
"productTypeId" : {
"type" : "integer"
},
"published" : {
"type" : "boolean"
},
"recurringCycleLength" : {
"type" : "integer"
},
"recurringCyclePeriod" : {
"type" : "long"
},
"recurringCyclePeriodId" : {
"type" : "integer"
},
"recurringTotalCycles" : {
"type" : "integer"
},
"requireOtherProducts" : {
"type" : "boolean"
},
"requiredProductIds" : {
"type" : "string"
},
"sampleDownloadId" : {
"type" : "integer"
},
"shortDescription" : {
"type" : "string"
},
"showOnHomePage" : {
"type" : "boolean"
},
"sku" : {
"type" : "string"
},
"specialPrice" : {
"type" : "double"
},
"specialPriceEndDateTimeUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"specialPriceStartDateTimeUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"specificationAttributeFilterItems" : {
"type" : "nested",
"properties" : {
"filterAttributeOptions" : {
"properties" : {
"filterId" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
},
"filterId" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
},
"stockQuantity" : {
"type" : "integer"
},
"subjectToAcl" : {
"type" : "boolean"
},
"tags" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "integer"
},
"name" : {
"type" : "string"
}
}
},
"taxCategoryId" : {
"type" : "integer"
},
"unlimitedDownloads" : {
"type" : "boolean"
},
"updatedOnUtc" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"userAgreementText" : {
"type" : "string"
},
"vendorId" : {
"type" : "integer"
},
"visibleIndividually" : {
"type" : "boolean"
},
"warehouseId" : {
"type" : "integer"
},
"weight" : {
"type" : "double"
},
"width" : {
"type" : "double"
}
}
}
}

An example of a product:

{

  • _index: defaultindex
  • _type: Product
  • _id: 17
  • _version: 1
  • _score: 1
  • _source: {
    • imageUrl: http://cdn.localhost.com/products/358981/358981_08.jpghttp://cdn.mode-mania.com/products/358981/358981_08.jpg
    • categories: [
      • {
        • appliedDiscounts: [ ]
        • name: Veterschoenen
        • description:
        • categoryTemplateId: 1
        • parentCategoryId: 2
        • pictureId: 0
        • pageSize: 24
        • allowCustomersToSelectPageSize: false
        • pageSizeOptions: 12,24,36,48,60
        • showOnHomePage: false
        • includeInTopMenu: true
        • hasDiscountsApplied: false
        • subjectToAcl: false
        • limitedToStores: false
        • published: true
        • deleted: false
        • displayOrder: 16
        • createdOnUtc: 2013-05-17T19:05:40.917
        • updatedOnUtc: 2013-05-28T06:54:51.03
        • id: 24
          }
          ]
    • manufacturers: [
      • {
        • name: Alberto Torresi
        • description: Wandel in stijl met deze Alberto Torresi's. Deze
          Alberto is één van s' werelds beste designers.
        • manufacturerTemplateId: 1
        • pictureId: 24226
        • pageSize: 40
        • allowCustomersToSelectPageSize: false
        • pageSizeOptions: 20, 40, 60, 80
        • subjectToAcl: false
        • limitedToStores: false
        • published: true
        • deleted: false
        • displayOrder: 0
        • createdOnUtc: 2013-02-28T14:40:54.883
        • updatedOnUtc: 2013-07-26T12:27:42.253
        • id: 68
          }
          ]
    • tags: [ ]
    • specificationAttributeFilterItems: [
      • {
        • name: Kleur
        • filterId: 1
        • filterAttributeOptions: [
          • {
            • name: Zwart
            • filterId: 15
              }
              ]
              }
      • {
        • name: Type
        • filterId: 10
        • filterAttributeOptions: [
          • {
            • name: Veterschoen
            • filterId: 133
              }
              ]
              }
      • {
        • name: Bovenmateriaal
        • filterId: 5
        • filterAttributeOptions: [
          • {
            • name: Leer
            • filterId: 70
              }
              ]
              }
      • {
        • name: Binnenvoering
        • filterId: 4
        • filterAttributeOptions: [
          • {
            • name: Leer
            • filterId: 67
              }
              ]
              }
      • {
        • name: Uitneembare zool
        • filterId: 6
        • filterAttributeOptions: [
          • {
            • name: Nee
            • filterId: 77
              }
              ]
              }
      • {
        • name: Seizoen
        • filterId: 7
        • filterAttributeOptions: [
          • {
            • name: Geen seizoen
            • filterId: 80
              }
              ]
              }
      • {
        • name: Status
        • filterId: 9
        • filterAttributeOptions: [
          • {
            • name: Sale
            • filterId: 195
              }
              ]
              }
              ]
    • productAttributeFilterItems: [
      • {
        • name: Maat
        • filterId: 1
        • filterAttributeOptions: [
          • {
            • name: 40
            • filterId: 13093
              }
          • {
            • name: 41
            • filterId: 13094
              }
          • {
            • name: 42
            • filterId: 13095
              }
          • {
            • name: 43
            • filterId: 13096
              }
          • {
            • name: 44
            • filterId: 13097
              }
          • {
            • name: 45
            • filterId: 13098
              }
              ]
              }
              ]
    • productTypeId: 5
    • parentGroupedProductId: 0
    • visibleIndividually: true
    • name: Alberto Torresi Veterschoen - Zwart
    • shortDescription:
    • fullDescription:
    • productTemplateId: 2
    • vendorId: 0
    • showOnHomePage: false
    • metaTitle: Zwarte Alberto Torresi Veterschoen In Leer Voor € 31,99
    • allowCustomerReviews: false
    • approvedRatingSum: 0
    • notApprovedRatingSum: 0
    • approvedTotalReviews: 0
    • notApprovedTotalReviews: 0
    • subjectToAcl: false
    • limitedToStores: false
    • sku: 358981
    • isGiftCard: false
    • giftCardTypeId: 0
    • requireOtherProducts: false
    • automaticallyAddRequiredProducts: false
    • isDownload: false
    • downloadId: 0
    • unlimitedDownloads: false
    • maxNumberOfDownloads: 10
    • downloadActivationTypeId: 0
    • hasSampleDownload: false
    • sampleDownloadId: 0
    • hasUserAgreement: false
    • isRecurring: false
    • recurringCycleLength: 100
    • recurringCyclePeriodId: 0
    • recurringTotalCycles: 10
    • isShipEnabled: true
    • isFreeShipping: false
    • additionalShippingCharge: 0
    • deliveryDateId: 0
    • warehouseId: 0
    • isTaxExempt: false
    • taxCategoryId: 0
    • manageInventoryMethodId: 2
    • stockQuantity: 10000
    • displayStockAvailability: true
    • displayStockQuantity: false
    • minStockQuantity: 0
    • lowStockActivityId: 0
    • notifyAdminForQuantityBelow: 0
    • backorderModeId: 0
    • allowBackInStockSubscriptions: false
    • orderMinimumQuantity: 1
    • orderMaximumQuantity: 10000
    • disableBuyButton: false
    • disableWishlistButton: false
    • availableForPreOrder: false
    • callForPrice: false
    • price: 31.99
    • oldPrice: 79.99
    • productCost: 0
    • customerEntersPrice: false
    • minimumCustomerEnteredPrice: 0
    • maximumCustomerEnteredPrice: 1
    • hasTierPrices: false
    • hasDiscountsApplied: false
    • weight: 0
    • length: 0
    • width: 0
    • height: 0
    • displayOrder: 0
    • published: true
    • deleted: false
    • createdOnUtc: 2013-02-28T18:19:08.697
    • updatedOnUtc: 2013-06-05T08:46:56.593
    • productType: 5
    • backorderMode: 0
    • downloadActivationType: 0
    • giftCardType: 0
    • lowStockActivity: 0
    • manageInventoryMethod: 2
    • recurringCyclePeriod: 0
    • id: 17
      }

}

This is the query i use:

http://localhost:9200/defaultindex/Product/_search

{
"query": {
"bool": {
"must": [
{
"constant_score": {
"filter": {
"terms": {
"product.categories.id": [
"24",
"7",
"8",
"9",
"16"
]
}
}
}
}
]
}
}
}

I'm I doing something wrong?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c086c5ad-7247-4d62-85e6-961234e26be5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Wesley, it sounds like you just need a standard "inner-object" mapping
instead of a "nested mapping". The nested mapping is indexed and queried
differently (i.e. you need to use the nested query/filter). In your case, I
would just remove the nested type from categories and your query should
work fine. Just double check the right casing of your field names when you
query them.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a89408d5-5901-48a5-a1a7-8b07cdc04296%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.